Reputation: 227
I have a problem regarding appending url params dynamically in angular 2. The angular 1 uses $location.search to add query params in the url. How could i achieve the same in 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);
})
}
Any help would be really appreciated!! Thankss a tonnn.
Upvotes: 0
Views: 2988
Reputation: 2148
In .ts
Use this._router.navigate(['/booking',{ id: 'keeping'}])
where /booking
is path and {id: 'keeping;}
In .html
Use [routerLink]="['/booking',{ service: 'keeping'}]"
where /booking
is path and {id: 'keeping;}
<a [routerLink]="['/booking',{ service: 'keeping'}]">Book</a>
Hope this helps.
Upvotes: 1