为什么@angular\router params 中的ActivatedRoute 是可观察的? [英] why ActivatedRoute in @angular\router params is observable?

查看:13
本文介绍了为什么@angular\router params 中的ActivatedRoute 是可观察的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 @angular\router params 中的 ActivatedRoute 是可观察的?

why ActivatedRoute in @angular\router params is observable ?

我想知道为什么我需要订阅 Params ?以及为什么 params 是异步的,是否会创建路由的组件,但 params 仍未填充?

I'm wondering why do I need to subscribe for Params ? and why params are async is there a case the componenet of the route will be created but the params still not populated ?

有没有办法在没有 observable 的情况下获取值?

and is there a way to just get the value without an observable ?

推荐答案

您可以使用

route.routerState.params

您可以订阅,因为当您的应用程序仅使用另一个参数值导航到同一路由时,不会重新创建组件,并且您无法知道参数何时发生更改.

You can subscribe because when your application navigates to the same route with just another parameter value, the component is not recreated and you have no way of knowing when the parameters have changes.

订阅参数后,您会收到通知,即发生了仅更改参数值的路由操作.

With subscribing to parameters you get notified, that a route action has happened where only the parameter value changed.

这篇关于为什么@angular\router params 中的ActivatedRoute 是可观察的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆