[英]Property does not exist on type in TypeScript
我正在处理离子4 create.page.ts
并且正在我的create.page.ts
验证表单,但是我尝试使用async方法并等待使用this.loading.ctrl
,但是我得到的错误描述如下标题。
另外,当我尝试处理其返回值时,也会在this.router.navigateByUrl('');
上收到错误this.router.navigateByUrl('');
如果不清楚到底发生了什么,这里是我的create.page.ts
:
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { LoadingController, AlertController } from '@ionic/angular';
import { FirestoreService } from '../../services/data/firestore.service';
@Component({
selector: 'app-create',
templateUrl: './create.page.html',
styleUrls: ['./create.page.scss'],
})
export class CreatePage implements OnInit {
public createConsultaForm: FormGroup;
constructor(
public firestoreService: FirestoreService, formBuilder: FormBuilder,
loadingCtrl: LoadingController, alertCtrl: AlertController
) {
this.createConsultaForm = formBuilder.group({
id: ['', Validators.required],
unidade: ['', Validators.required],
medNome: ['', Validators.required],
especialidade: ['', Validators.required],
endereco: ['', Validators.required],
data: ['', Validators.required],
hora: ['', Validators.required],
});
}
ngOnInit() {
}
async createConsulta() {
const loading = await this.loadingCtrl.create();
const id = this.createConsultaForm.value.id;
const unidade = this.createConsultaForm.value.unidade;
const medNome = this.createConsultaForm.value.medNome;
const especialidade = this.createConsultaForm.value.especialidade;
const endereco = this.createConsultaForm.value.endereco;
const data = this.createConsultaForm.value.data;
const hora = this.createConsultaForm.value.hora;
this.firestoreService
.createConsulta(unidade, especialidade, medNome, endereco, data, hora)
.then(
() => {
loading.dismiss().then(() => {
this.router.navigateByUrl('');
});
},
error => {
console.error(error);
}
);
return await loading.present();
}
}
在这行上:
const loading = await this.loadingCtrl.create();
我得到:
类型“ CreatePage”上不存在属性“ loadingCtrl”
在这一行上:
this.router.navigateByUrl('');
我懂了
类型“ CreatePage”上不存在属性“ router”
我看不到您导入Router
任何地方
导入Router
并在构造函数中实例化
constructor(router: Router) { this.router.navigateByUrl(...); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.