【发布时间】:2018-06-02 13:08:10
【问题描述】:
我是 Angular 新手,如果我对术语的理解不正确,请纠正我。
在我需要读取子组件中的路由参数值的示例应用程序上工作。我能够打印“参数”对象,但无法提取其中的数据。只需粘贴我的代码,以便我可以提供更多详细信息:
客户详细信息组件:
ngOnInit() {
this.route.parent.params.subscribe((params: Params) => {
console.log( params);
console.log("Id value" + params['id']);
if (1) {
this._custServ.getCustomerDetailsById(1)
.subscribe((customer: ICustomer) => {
this.customer = customer;
//s console.log(customer.id);
});
}
});
}
我正在访问的网址:http://localhost:4200/customers/1/details
谷歌浏览器控制台:
我从一天开始就尝试获取参数值,但没有运气。在这种情况下你能指导我吗?
谢谢 普拉桑特
根据 Sujeethan 的指导更新了代码,但现在我收到了 id 作为空值。下面组件的完整代码。 Code
【问题讨论】:
标签: angular typescript