简体   繁体   English

未填充 Angular 7 可选参数

[英]Angular 7 optional parameter not populated

I have been attempting to follow along with the optional route parameters section of the angular documentation, in order to add and operate with optional parameters on some routes in my own application.我一直在尝试遵循 angular 文档的可选路由参数部分,以便在我自己的应用程序中的某些路由上添加和操作可选参数。

However, there is clearly something I am missing or not understanding, as I cannot get this to work.但是,显然我遗漏或不理解某些东西,因为我无法让它发挥作用。

The expected behaviour: when clicking the router links the text changes to show the optional parameter.预期行为:单击路由器链接时,文本会更改以显示可选参数。

Actual behaviour: the parameter value is never defined.实际行为:从未定义参数值。

I have created a stackblitz forked from a template and reproduced the problem as simply as I can.我创建了一个从模板分叉的 stackblitz,并尽可能简单地重现了这个问题。

https://stackblitz.com/edit/angular-7-master-9c4dwm https://stackblitz.com/edit/angular-7-master-9c4dwm

You can extract your parameter after subscribing to the paramMap as below:您可以在订阅paramMap后提取您的parameter ,如下所示:

this.route.paramMap.subscribe((parameters: any) => {
  this.parameter = parameters.params.parameter;
});

See the updated plunk.查看更新的 plunk。

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

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