我有一个问题就是在角度2中动态追加url params。角度1使用$ location.search在url中添加查询参数。我如何在Angular 2中实现相同的目标?
//Api call to submit product details
submit_product() {
let model = new AddProductModel(this.post_dict.name, this.post_dict.slug, 'N', 0, this.post_dict.display_sitewide, this.post_dict.display_in_party, JSON.parse(localStorage.getItem('bundled')), 'N', parseInt(JSON.parse(localStorage.getItem('categories'))));
this
.product
.addProduct(model)
.then(productObj => {
if (productObj) {
localStorage.removeItem('categories');
// Here i wish to set the object id as the URL parameter;
this.successMessage = 'Product Information added Successfully';
this.timeoutMethod(true);
}
})
.catch(error => {
this.errorMessage = error.error.message;
this.timeoutMethod(false);
})
}
任何帮助都会非常感激!!感谢tonnn。
答案 0 :(得分:1)
在.ts
使用this._router.navigate(['/booking',{ id: 'keeping'}])
其中/booking
为路径且{id: 'keeping;}
在.html
使用[routerLink]="['/booking',{ service: 'keeping'}]"
其中/booking
为路径且{id: 'keeping;}
<a [routerLink]="['/booking',{ service: 'keeping'}]">Book</a>
希望这有帮助。