我正在处理离子4杂物,并且在我的create.page.ts
中正在验证表单,但是我试图使用异步方法并等待使用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”上不存在属性“路由器”
答案 0 :(得分:-1)
我看不到您导入Router
的任何地方
导入Router
并在构造函数中实例化
constructor(router: Router) { this.router.navigateByUrl(...); }