Search code examples
javascriptangularjsurlangularjs-routing

How to build custom URL by adding ?&params in Angular?


I'm trying to build a custom URL and update the URL as the user selects items in my dashboard.

For example, after clicking a few items the URL could/should look like:

#/dashboard?&portfolio=GOOG&ticker1=GOOG

Currently the URL only ends in /dashboard (console.log($location.path());)

How would I update the $location.path() to add params like so? There's plenty of questions/answers and guides on getting params from the URL, but how would you update the URL in the first place?

Say if you want to add the following:

  • ?&portfolio=GOOG&ticker1=GOOG

Solution

  • just organize your params in an object, like

    var params = {
       portfolio: GOOG,
       ticker1:GOOG
    }
    

    and use,

    $location.url('/dashboard ').search(params);
    

    Hope it helps !!!