how to refresh page in angular 2

后端 未结 6 1397
情话喂你
情话喂你 2021-02-02 08:19

I have created one router link as below. This router link loads ProductsStartComponent and then this component loads several other components using ngif and not via

6条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-02 09:04

    Just in case someone else encounters this problem. You need to call

    window.location.reload()
    

    And you cannot call this from a expression. If you want to call this from a click event you need to put this on a function:

    (click)="realodPage()"
    

    And simply define the function:

    reloadPage() {
       window.location.reload();
    }
    

    If you are changing the route, it might not work because the click event seems to happen before the route changes. A very dirty solution is just to add a small delay

    reloadPage() {
        setTimeout(()=>{
          window.location.reload();
        }, 100);
    }
    

提交回复
热议问题