Angular Treatment of JSON

0

I wonder if it is necessary to handle JSON to use the two-way databinding in HTML. I managed to read it without the treatment, but I do not know if this is the correct way.

Follow 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]);
      }
  )}
    
asked by anonymous 28.09.2018 / 00:36

1 answer

0

You do not need any treatment.

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

I hope I have helped.

    
08.10.2018 / 04:39