Reputation: 276
I am developing an app, using Ionic 3 with angular 4. And I have the following problem: How can I pass an array of the object from a page, to a component?
When I inform the object in my directive to the component, it is converted to a string with the following information:
[Object object], [Object object], [Object object]
...
Page.html (page) code:
<ion-card *ngFor="let telemetry of listTelemetry">
<telemetria-chart medicao="{{telemetry.medicoes}}"></telemetria-chart>
</ion-card>
Original value of 'telemetry.medicoes' :
TelemetriaChart.ts (compenent) code:
@Component({
selector: 'telemetria-chart',
templateUrl: 'telemetria-chart.html'
})
export class TelemetriaChartComponent {
@ViewChild('myChart') canvas: ElementRef;
@Input() funcionalidadeId: any;
@Input() medicao: any [];
text: string;
constructor() {
setTimeout(() => {
console.log('this.medicao', this.medicao);
//...do something with this.medicao
}, 1000);
}
}
Result from console.log(this.medicao):
I need to get info from 'this.medicao'.
Upvotes: 2
Views: 3643
Reputation: 5748
Change
medicao="{{telemetry.medicoes}}"
to
[medicao]="telemetry.medicoes"
Helpful link for you:
There you can read about {{}}
. Where we need use and what interpolation do with data inserted in it.
And there you can read about component communication scenarios that we can use in angular2
Upvotes: 3