0

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.

5
  • Use this._router.navigate(['/booking',{ id: 'keeping'}]) where /booking is path and {id: 'keeping;} is the id that you wish to pass Commented Feb 27, 2017 at 17:26
  • How is the code you provided even related to your question? I see no url there anywhere? And url with parameter, do you mean a http call or routing? :) Commented Feb 27, 2017 at 21:16
  • @Smit Thankss a tonnn it really helped!!! Commented Mar 1, 2017 at 16:52
  • Hope that helped @AbhijeetChakravorty I have added that as a answer, if you require any more help, let me know. Commented Mar 1, 2017 at 16:58
  • 1
    @Smit thankss a tonn will stay in touch :D . Commented Mar 1, 2017 at 17:14

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.