属性 'custom' 在类型 'EventEmitter<any>' 上不存在

Property 'custom' does not exist on type 'EventEmitter<any>'

我正在使用 ionic 3,我有一个 part 组件和一个 parts page

Parts.html 页数:

<ion-row> 
   <part [part]="part"></part>
</ion-row>

parts.html的部分变量是这个json:

Part.ts分量:

import { Component, ViewChild, Input, EventEmitter } from "@angular/core";

export class PartComponent {
    @Input() part = new EventEmitter<any>();

    ngAfterViewInit(){
        this.setInitialValues();
    }
    ngOnChanges(){
        this.setInitialValues();
    }

    setInitialValues() {
      console.log(this.part);
      if (this.part) {

        if (this.part.hasOwnProperty('parts') && this.part.parts.length != 0) {
          this.hasParts = true;
        }
        this.getPartQuestionnaire(this.part.id);
      }
    }

我在构建离子应用程序时遇到此错误:

属性 'parts' 在类型 'EventEmitter' 上不存在。

L81: if (this.part.hasOwnProperty('parts') && this.part.parts.length != 0) {

L82: this.hasParts = true;

属性 'id' 在类型 'EventEmitter' 上不存在。

L84: this.getPartQuestionnaire(this.part.id);

当我评论 part.ts 的这一行并在控制台中显示变量部分时,我得到了 fowow 图像表示,其中前 2 个调用显示为空,但在它加载部分值之后:

在尝试构建应用程序时如何解决此错误?

我正在使用 ionic cordova run browser

构建

尝试换行

来自

 @Input() part = new EventEmitter<any>();

@Input() part : any;

您的代码示例中存在多处错误。

1.@Input 用于接受来自父组件的数据,而我们使用 带有 @Output 装饰器的 EventEmitter。你把它们混在一起了。

2.when你写了:

@Input() part = new EventEmitter<any>();

表示变量part现在是EventEmitter类型,而不是Part类型。

要使其正常工作,请按照@Sajeetharan 的建议更改零件类型,或者像这样:

@input Part: IPart; // IPart is an interface which matches the structure of your data.
@Output myOutput = new EventEmitter<any>();