How to read an array string in Ionic/Angularjs or Javascript and move to directives?

Asked

Viewed 513 times

0

I passed parameters to another TS with:

console.log('Data', navParams.get('sessoes'));

That shows me this result:

{data: "2018-09-11", weight: "200", sessoes: "20", repeticoes: "2", notas: "teste"}

This way I can catch each of the fields in the Array:

var object = navParams.get('sessoes');    
      console.log(object["data"]);
      console.log(object["weight"]);
      console.log(object["sessoes"]);
      console.log(object["repeticoes"]);
      console.log(object["notas"]);

Now I need to take this data to be shown in a form that has [(ngModel)]="sessao.data", [(ngModel)]="sessao.weight", [(ngModel)]="sessao.sessoes", etc....

How to place these objects in an ngModel directive for my Ionic/Angular form?

1 answer

0


Create an object within the class called sessao or create and extend an interface

Then pass this created object inside your method to receive data from the array

 sessao = {data: '', weight: '', sessoes: '', repeticoes: 'repeticoes', notas: ''}

      constructor() {
        let object = navParams.get('sessoes');    
        this.sessao.data = object["data"];
        this.sessao.weight = object["weight"];
        this.sessao.sessoes = object["sessoes"];
        this.sessao.repeticoes = object["repeticoes"];
        this.sessao.notas = object["notas"];
  }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.