Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
Realtime Update and view rendering

I have a data service to communicate with my server.

export class DataService {
  constructor(private http: Http) { }

  getUsers():Observable<Users>{


    return this.http.get(myurl).map(this.extractData);

 }
extractData(res:Response){

    return res.json();
  }
}

I use it inside my component in this way.

ngOnInit() {
    this.getUsers();
  }

  getUsers():void{

    this.dataService.getUsers().subscribe(response=>{
      this.users = response;


    } );

  }

The variable this.user is a input for a table. When I start the component before I see the empty table and after,when the data are loaded, I see the table with all the users. How Can I view the component just when the data are ready?

When I insert a new user on my server I don't see it on my table and I need to refresh the page. How Can I show(real time) a new user on the table, after an insert, without refresh the page?

Thank you

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

How Can I view the component just when the data are ready?

You need to move this data retrieval logic into a Resolver and the component should get data from it.

How Can I show(real time) a new data on the table, after an insert, without refresh the page?

You should intitiate the data retrieval logic on insert inside of your component and update the reference to 'users' variable with new data.

over 4 years ago · Santiago Trujillo Relatório

0

You can always initialize this.users to null. Then in your markup you could do something like this:

<div *ngIf="users">
   <!-- Your content here -->
</div>

When users becomes non-null Angular will begin rendering the div tagged with *ngIf. This works because in JS null is falsy. If that seems goofy you could always set a boolean flag in your subscription that you reference in the *ngIf block (*ngIf="myFlag").

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda