且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Angular2 如何在使用路由的组件之间更改时再次加载 javascript

更新时间:2023-02-13 23:30:18

当导航仅更改路由参数时,目前无法让 Angular2 路由器重新创建组件.有计划支持这一点.

Currently there is no way to make the Angular2 router recreate the component when the navigation only changes a route parameter. There are plans to support that.

您可以通过订阅路由参数更改并在那里执行代码来解决

You can work around by subscribing to route parameter changes and execute the code there

constructor(private route:ActivatedRoute) {}

ngOnInit() {
  route.params.subscribe(p => {
    this.myInit(); // successive params changes
  });
  this.myInit(); // first time
}

myInit() {
  jQuery($('.selectpicker').selectpicker()';
}