Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 组件重新加载时的角度非惯性力发射_Angular_Angular2 Routing - Fatal编程技术网

Angular 组件重新加载时的角度非惯性力发射

Angular 组件重新加载时的角度非惯性力发射,angular,angular2-routing,Angular,Angular2 Routing,我正在使用Angular2,并将为每个帐户加载设置页面上的内容 下面是URL结构 URL1 http://example.com/account/NICKNAME_1/settings URL2 http://example.com/account/NICKNAME_1/orders URL3 http://example.com/account/NICKNAME_2/settings URL4 http://example.com/account/NICKNAME_2/orders 如果我

我正在使用Angular2,并将为每个帐户加载设置页面上的内容

下面是URL结构

URL1 http://example.com/account/NICKNAME_1/settings
URL2 http://example.com/account/NICKNAME_1/orders

URL3 http://example.com/account/NICKNAME_2/settings
URL4 http://example.com/account/NICKNAME_2/orders
如果我要从URL1到URL3(或URL3到URL1),则
ngOnInit
不会为
设置组件启动。
这是预期的行为,因为Angular尝试不重新加载组件

订阅
设置组件中的更改参数不能解决问题,因为没有参数

如何检测
设置组件
中帐户名的更改

订阅设置组件中的更改参数无法解决问题,因为没有参数

您将在路由父级上找到作为参数的帐户名:

route.parent.params.subscribe(...)

当然有一个参数,名字。它只是在route.parent上,除非您将其配置为向下传递参数。此外,如果您确实想强制组件重新初始化,您可以编写自己的组件重用策略。但是这里没有理由这么做,太好了。route.parent.params上的订阅有帮助。谢谢我把它添加为一个答案,这样你就可以接受它(如果你愿意的话,可以向上投票),这样问题就被标记为已解决。