Angular 属性在TypeScript中的类型上不存在
我正在处理ionic 4 crud,在我的Angular 属性在TypeScript中的类型上不存在,angular,typescript,ionic-framework,google-cloud-firestore,Angular,Typescript,Ionic Framework,Google Cloud Firestore,我正在处理ionic 4 crud,在我的create.page.ts中,我正在验证表单,但是我尝试使用异步方法,并等待使用this.loading.ctrl,但是我在标题上看到了这个错误 另外,当我尝试处理它的返回时,我在this.router.navigateByUrl(“”)上也得到了一个错误如果不清楚这里到底发生了什么,下面是我的create.page.ts: import { Component, OnInit } from '@angular/core'; import { Form
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();
this.router.navigateByUrl('');
我得到:
类型“CreatePage”上不存在属性“loadingCtrl”
在这一行:
const loading = await this.loadingCtrl.create();
this.router.navigateByUrl('');
我明白了
类型“CreatePage”上不存在属性“router”
我看不到你导入路由器的任何地方 导入
路由器
并在构造函数内实例化
constructor(router: Router) { this.router.navigateByUrl(...); }
你能说出全部错误吗?哪些财产不存在?错误在哪一行?我已经编辑了我的帖子,以更清晰地显示错误。有些人刚刚发布了解决方案,但他们删除了答案lol@AJT_82,是的,因为我使用它作为类型angular,从我通过Click生成项目时开始!我忘了将它添加到我的构造函数中,还声明了加载控制器是公共的,谢谢!我站在更正,以及没有与v4,所以这是我的借口:PGreat!我也对AJT的评论感到困惑。如果这有帮助,请投票