简体   繁体   English

重新加载组件时,角度ngOnInit强制触发

[英]Angular ngOnInit force firing when component reload

I'm using Angular2 and gonna load content on Settings page for every account. 我正在使用Angular2,并将在每个帐户的Settings page上加载内容。

URL structure below 网址结构如下

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

If I'm going from URL1 to URL3 (or URL3 to URL1) then ngOnInit doesnt fire for settings component . 如果我要从URL1到URL3(或从URL3到URL1),则ngOnInit不会为settings component触发。 This is expected behavior because Angular trying not to reload component. 这是预期的行为,因为Angular尝试不重新加载组件。

Subscribing on changing params in settings component doesnt solve the issue because there are no parameters. 订阅更改settings component参数并不能解决问题,因为没有参数。

How can I detect changing Account name inside of Settings component ? 如何在“ Settings component检测更改的帐户名?

Subscribing on changing params in settings component doesnt solve the issue because there are no parameters. 订阅更改设置组件中的参数并不能解决问题,因为没有参数。

You'll find the account name as a param on the route parent: 您会在路由父级上找到帐户名称作为参数:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM