且构网

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

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

更新时间:2021-08-04 23:09:50

当前,当导航仅更改路线参数时,无法使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()';
}