Angular 如果url中存在特定参数,请更改变量
如何使用this.router.url检查我的url是否包含id等特定参数? 在一个例子中,如果url有配置文件来更改搜索图标,我将使用以下内容。我想对user/videos/:id执行相同的操作,但仅当id参数存在于url中时Angular 如果url中存在特定参数,请更改变量,angular,router,Angular,Router,如何使用this.router.url检查我的url是否包含id等特定参数? 在一个例子中,如果url有配置文件来更改搜索图标,我将使用以下内容。我想对user/videos/:id执行相同的操作,但仅当id参数存在于url中时 if (this.url.includes("profile")) { this.searchIcon = true; } 对于快速修复,您可以使用来自的快照 从'@angular/router'导入{Activate
if (this.url.includes("profile")) {
this.searchIcon = true;
}
对于快速修复,您可以使用来自的快照
从'@angular/router'导入{ActivatedRoute};
...
导出类SomeComponent实现OnInit{
id:任何;
构造函数(私有_activatedRoute:activatedRoute){
恩戈尼尼特(){
this.id=this._activatedRoute.snapshot.paramMap.get('id');
如果(!!this.id){
//`id`已定义
}否则{
//`id`未定义
}
}
}