-1

I have a page where in my ngOnInit I check from where I arrive (for example, if I arrive from page1 I set a variable that I use to show an html, or from page2 another variable to show another html)

ngOnInit() {
       this.handleParams();
}


handleParams(){
    this.isNewCustomer = JSON.parse(
      localStorage.getItem(LocalstorageKeyEnum.NEW_CUSTOMER)
    );

    let params = this.route.snapshot.queryParams;
    if (params.customerCreate === true) {
      this.customerCreate = true;
    }

    this.isUpdate = JSON.parse(
      localStorage.getItem(LocalstorageKeyEnum.IS_UPDATE)
    );
}

Now I notice that this my ngOnInit() is called only one time, so every time I enter in the page I The handleParams is not checked.

How can I get the ngOnInit called?

Jack23
  • 1,368
  • 7
  • 32

1 Answers1

0

What is your correct question? Is ngOnInit called once or never? It's correct when it's called just once you entering the page. Maybe your routing to the localStorage is wrong? It's just a simple call - e. g.:

localStorage.setItem('savePage', setUrlFromPage);
const myPage = localStorage.getItem('savePage');