在Angular 2中,我的queryParams订阅被调用两次?

时间:2017-10-05 06:32:37

标签: angular asynchronous subscription url-parameters queryparam

这是正常行为吗?是否在启动时调用它以及何时加载queryParams?

我在我的ngOnInit()中订阅了我的queryParams,如下所示:

this.subscription = this.editorService.paramObs.subscribe(
    (params: Params) => {
        /* my code here gets executed two times */
    }
)

1 个答案:

答案 0 :(得分:0)

您需要取消订阅组件销毁。查看更多详情:http://brianflove.com/2016/12/11/anguar-2-unsubscribe-observables/