TypeScript中的类型不存在属性

诺克

我正在处理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”

萨耶塔兰(Sajeetharan)

我看不到您导入的任何地方 Router

Router在构造函数中导入并实例化

constructor(router: Router) { this.router.navigateByUrl(...); }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

TypeScript中的EventTarget类型不存在属性“值”

TypeScript中的“ EventTarget”类型错误不存在属性“文件”

Typescript属性“ length”在类型上不存在

TypeScript错误:类型“ Navigator”上不存在属性“ app”

“类型中不存在属性”

Typescript中的类型“ Date”上不存在属性“ getWeek”

类型'FileList'上不存在TypeScript属性'forEach'

枚举类型不存在Typescript属性

在Typescript Reac + Redux中具有联合类型的类型错误时属性不存在

TypeScript + Express:类型“ IncomingMessage”上不存在属性“ rawBody”

类型'ChildNode [Typescript]上不存在属性'tagName'

属性“类型”不存在

TypeScript Joi:类型“ Root”上不存在属性“ validate”

Typescript:组合类型不存在属性?

TypeScript:类型上不存在属性“范围”

Typescript中的XXX类型不存在属性'forEach'

TypeScript 4-类型编号不存在属性查找[]

属性“名称”在类型“ EventTarget”上不存在-React + TypeScript

TypeScript类型不存在属性“ load”?

类声明-TypeScript中的类型不存在属性

服务中的类型不存在属性

使用TypeScript时获取类型的属性不存在错误

Typescript 属性在类型元素上不存在

Typescript 的“对象”错误类型上不存在属性

在声明对象后添加属性时,在 TypeScript 中获取“类型上不存在属性‘FOO’”

与 TypeScript 反应 - 类型“EventTarget”上不存在属性“value”

TypeScript - 类型上不存在属性(但它存在)?

ReactJS 中的 Typescript 错误 - 类型上不存在属性

TypeScript:禁止联合类型的“类型上不存在属性”