改写我之前的问题,我有这条路线,它给了我这样的东西 /order-screen/store/1/London
{
path: 'order-screen/store/:storeId/:storeLocation',
component: OrderComponent
}
Run Code Online (Sandbox Code Playgroud)
当我尝试storeLocation使用this.route.params它时,它会返回NaN. 我想知道位置London,不确定是否.params适合使用。
this.routeSub = this.route.params.subscribe(params => {
this.storeLocation = +params['storeLocation'];
console.log('Location >> ', this.storeLocation);
})
Run Code Online (Sandbox Code Playgroud)
只需+从您的参数之前删除。所以..
this.routeSub = this.route.params.subscribe(params => {
this.storeLocation = params['storeLocation'];
console.log('Location >> ', this.storeLocation);
})
Run Code Online (Sandbox Code Playgroud)
在+将一个字符串转换为一个号码,因为“伦敦”是不是一个数字,你得到了错误的NaN
| 归档时间: |
|
| 查看次数: |
3377 次 |
| 最近记录: |