Angular : how to update the variable in html automatically when its value is changed in file . ts?

Asked

Viewed 428 times

0

I have a variable that gets value when the page renders, and it looks right in the template. However if I change its value with the page already loaded the value in . ts is updating (checked with console.log) but in html remains unchanged.

HTML:

<ion-list *ngFor="let linhacred of linha" style="font-family: 'Nunito', sans-serif;">
<h5>Nome: {{linhacred.nome}}</h5>
</ion-list>

TS:

let options = new RequestOptions({ headers: headers });
    let str = Object.entries(dados).map(([key, val]) => `${key}=${val}`).join('&');
    this.http.post(this.apiUrl, str, options).subscribe(data => {
      const obj = (data as any);
      const obj_json = JSON.parse(obj._body);
      this.linha_credito = obj_json;
      this.global.gotoFinalView(this.linha_credito);
      console.log(this.linha_credito);
      this.router.navigate(['/tabs/tab3']);
  • 1

    Hello. Where is the line variable in your TS? Would that be line credit? Use Changedetectorref to detect TS changes and render on the screen. At the end of the updating function, call "this.cdr.detectChanges()". More about: https://angular.io/api/core/ChangeDetectorRef

  • in that your ts you are not changing the property line

  • @Gesielrosa I pasted here the TS of the page that sends the information to another screen (Which is then displayed and which has the variable line mentioned by Voce. I haven’t been able to solve the problem with the function mentioned, could you assist me yet? Follows TS from the cited page: export class Tab3page { line: any; constructor(global private: Globalprovider, private router: Router) { this.return_simulation(); } public return_simulation(){ this.line = this.global.getDestn(); console.log(this.line); this.todas_simulations = this.line; } }

No answers

Browser other questions tagged

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