我正在处理Ionic 4 Crud,create.page.ts
正在验证表单,但是我尝试使用async方法并等待使用this.loading.ctrl
,但是标题中描述了此错误。
另外,当我尝试处理它的返回值时,我也会收到一条错误消息,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(...); }
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句