2

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' : enter image description here

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): enter image description here

I need to get info from 'this.medicao'.

5
  • I do not understand you want to set single object from medicao array or all medicao array. And what data listTelemetry. Before you answer this questions fix these problems: [medicao]="telemetry.medicoes". You need to use [ ]. And not need to use {{ }}. Because we do not stringify it. Read here angular.io/guide/template-syntax Commented Oct 5, 2017 at 22:03
  • Thanks @RomaSkydan, I'll make a correction. I expressed myself, the doubt was so much for single object for list of object. But the list is a priority. Commented Oct 5, 2017 at 22:16
  • @RomaSkydan, your suggestion to switch medicao = "{{telemetry.medicoes}}" to [medicao] = "telemetry.medicoes", it worked! Thank you. Do you want to write your answer? Commented Oct 5, 2017 at 22:18
  • do we fix your problem? Or something left? Commented Oct 5, 2017 at 22:21
  • yeah, it's fix my problem Commented Oct 5, 2017 at 22:45

1 Answer 1

3

Change

medicao="{{telemetry.medicoes}}"

to

[medicao]="telemetry.medicoes"

Helpful link for you:

Angular Interpolation

There you can read about {{}}. Where we need use and what interpolation do with data inserted in it.

Component Interaction

And there you can read about component communication scenarios that we can use in angular2

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.