How to listen to a request in Angular 4

1

I'm doing an Http request in Angular 4, but I need to listen to it and show it in the template in real time, that is to say the extent to which it is being registered, the information will appear on the grid automatically.

ngOnInit() {

    this.userService.lista()
    .subscribe(data => {  this.usuarios = data });
}

Is this the return of the request in the component can help me?

    
asked by anonymous 07.12.2017 / 15:15

2 answers

0

Creates an attribute on the page to make the property bind:

@Input() meuAtributo: any;// o tipo você que define

this.userService.lista()
    .subscribe( (data: any) => {
       this.meuAtributo = data;
        console.log(this.meuAtributo, data);
    });
<h2 [(ngModel)]="meuAtributo"></h2>
    
07.12.2017 / 16:30
0

Good morning, you can use an interval

atualizarDados(){
  this.userService.lista()
 .subscribe(data => {  this.usuarios = data });
}

window.setInterval(atualizarDados, 600);

This will do every 600 ms this route is called ...

    
21.08.2018 / 13:20