Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

197
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!