Angular 2 ngOnInit is not called when routerlink changes

前端 未结 3 1231
故里飘歌
故里飘歌 2021-01-06 12:31

i have a menu bar that contain a list of menus loaded from express api and every menu is referenced to a page that have an alias wich will be the URL of tha

3条回答
  •  伪装坚强ぢ
    2021-01-06 13:28

    Here is a code example of what Gunter is talking about:

      constructor(private route: ActivatedRoute) { }
    
      ngOnInit() {
         this.route.params.subscribe(
         params => {
            let id= +params['id'];
            this.getProduct(id);
         });
      }
    

    This code watches for changes to the parameters and executes any code inside the arrow function.

提交回复
热议问题