Angular Treatment of JSON

Asked

Viewed 48 times

0

I would like to know if it is necessary to process JSON to use two-way databinding in HTML. I was able to read it without the treatment, but I don’t know if this is the right way.

Follows the code:

ngOnInit() {
  this.emissor = 'Luis Henrique';
  this._http.get<PreparacaoDeMensagem[]>("../assets/db/mensagem.json")
    .subscribe(mensagem => {
      this.mensagem = mensagem        
      for (let i=0;i < mensagem.length;i++){
        this.adicionarMensagem(this.mensagem[i]);
      }
  )}

1 answer

0

Doesn’t need any treatment.

Javascript objects are treated as objects and the return json of your http service call is automatically transformed into a ready-to-use, native javascript object.

I hope I’ve helped.

Browser other questions tagged

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