Angular ngOnInit 在组件重新加载时强制触发
Angular ngOnInit force firing when component reload
我正在使用 Angular2 并将在 Settings page
上为每个帐户加载内容。
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
不会触发 settings component
。
这是预期的行为,因为 Angular 尝试不重新加载组件。
在 settings component
中订阅更改参数并不能解决问题,因为没有参数。
如何检测 Settings component
中帐户名称的更改?
Subscribing on changing params in settings component doesnt solve the issue because there are no parameters.
您会在路由父级上找到作为参数的帐户名称:
route.parent.params.subscribe(...)
我正在使用 Angular2 并将在 Settings page
上为每个帐户加载内容。
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
不会触发 settings component
。
这是预期的行为,因为 Angular 尝试不重新加载组件。
在 settings component
中订阅更改参数并不能解决问题,因为没有参数。
如何检测 Settings component
中帐户名称的更改?
Subscribing on changing params in settings component doesnt solve the issue because there are no parameters.
您会在路由父级上找到作为参数的帐户名称:
route.parent.params.subscribe(...)