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

107
Views
ngOnInit does not get invoked when routing to same component again - Angular 2

I'm working on angular 2 webapp, I navigate to xyz component when I have data in my array and stores it in service component. The xyz component's ngOnInit() method get data from service and displays it to its html template. The problem is that when my source array data changes I'm redirecting to xyz component again but then xyz's ngOnInit() method does not get invoked this time. Is there any way to achieve this ?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You could subscribe to an event in your component. I don't know how to integrate this to you code, but on mine it looks like this :

ngOnInit() {
    this._events.xyz.onDataChange.subscribe (() => {
        this.onDataChange();
    }
onDataChange() {
    // Display to HTML Template
}

And then, when your data changes, you use this._events.xyz.onDataChange().publish()

I'm using a TypeScript class EventsManager, you can probably do this kind of things with angular's events.

You should wait for answers from more experienced developers though.

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!