为什么在@angular \ router参数中看到ActivatedRoute? [英] why ActivatedRoute in @angular\router params is observable?

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

问题描述

为什么@angular\router params is observable中的ActivatedRoute?

我想知道为什么我需要订阅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参数中看到ActivatedRoute?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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