Reputation: 553
I'm using ionic 3, and I have a part component and a parts page
Parts.html page:
<ion-row>
<part [part]="part"></part>
</ion-row>
The part variable of parts.html is this json:
Part.ts component:
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);
}
}
I'm getting this errors when i'm building the ionic app:
Property 'parts' does not exist on type 'EventEmitter'.
L81: if (this.part.hasOwnProperty('parts') && this.part.parts.length != 0) {
L82: this.hasParts = true;
Property 'id' does not exist on type 'EventEmitter'.
L84: this.getPartQuestionnaire(this.part.id);
When I comment this lines of part.ts and show in console the variable part, I get the foow image representation, where the first 2 calls appear null, but after it load the part values:
How can I solve this error when I try to build the app?
I'm building with ionic cordova run browser
Upvotes: 0
Views: 2865
Reputation: 2508
There multiple things wrong in your code example.
1.@Input is used to accept the data from a parent component whereas we use EventEmitter with the @Output decorator. You have mixed them.
2.when you have written:
@Input() part = new EventEmitter<any>();
it means the variable part is of type EventEmitter now and not type Part.
To make it work either change the type of part as @Sajeetharan has suggested or like this:
@input Part: IPart; // IPart is an interface which matches the structure of your data.
@Output myOutput = new EventEmitter<any>();
Upvotes: 1
Reputation: 222722
Try changing the line
From
@Input() part = new EventEmitter<any>();
To
@Input() part : any;
Upvotes: 1