且构网

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

如何手动重新渲染组件?

更新时间:2023-12-02 20:07:46

不需要重新加载组件.只需更新模型,视图即会更新:

There shouldn't be a need to reload the component. Just update the model and the view updates itself:

export class MyComponent {
    constructor(private route : ActivatedRoute,
      private r : Router) {}

    reloadWithNewId(id:number) {
        this.r.navigateByUrl('my/' + id + '/view');
    }

    ngOnInit() {
      this.sub = this.route.params.subscribe(params => {
         this.paramsChanged(params['id']);
       });
    }

    paramsChanged(id) {
      console.log(id);
      // do stuff with id

    }
}