AngularJS: How to clear query parameters in the URL?

后端 未结 16 2488
余生分开走
余生分开走 2020-12-04 14:40

My AngularJS application needs to have access to the user\'s LinkedIn profile. In order to do that I need to redirect the user to a LinkedIn URL which contains a callback re

相关标签:
16条回答
  • 2020-12-04 15:35

    If you are using routes parameters just clear $routeParams

    $routeParams= null;
    
    0 讨论(0)
  • 2020-12-04 15:37

    To clear an item delete it and call $$compose

        if ($location.$$search.yourKey) {
            delete $location.$$search.yourKey;
            $location.$$compose();
        }
    

    derived from angularjs source : https://github.com/angular/angular.js/blob/c77b2bcca36cf199478b8fb651972a1f650f646b/src/ng/location.js#L419-L443

    0 讨论(0)
  • 2020-12-04 15:37

    If you want to move to another URL and clear the query parameters just use:

    $location.path('/my/path').search({});
    
    0 讨论(0)
  • 2020-12-04 15:40

    I can replace all query parameters with this single line: $location.search({});
    Easy to understand and easy way to clear them out.

    0 讨论(0)
  • 2020-12-04 15:41

    How about just setting the location hash to null

    $location.hash(null);
    
    0 讨论(0)
  • 2020-12-04 15:42

    To remove ALL query parameters, do:

    $location.search({});
    

    To remove ONE particular query parameter, do:

    $location.search('myQueryParam', null);
    
    0 讨论(0)
提交回复
热议问题