Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I wants to refresh a page for only one time using angular 7.

What I have tried:

I have tried
ngOnInit(){
      let win = (window as any);
      if(win.location.search !== '?loaded' ) {
          win.location.search = '?loaded';
          win.location.reload();
      }
  }

but this code refresh the page continuously.
Posted
Updated 3-Mar-20 3:27am

1 solution

Assigning a value to location.search will reload the page using the new URL.

But you immediately call location.reload after that, which reloads the page using the current URL, which doesn't include the new search parameter.

Remove the call to reload, and your code should work.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900