How can I set a query parameter in AngularJS without doing a route?

前端 未结 1 1539
春和景丽
春和景丽 2020-12-22 19:28

My Angular app allows the user to load an item, and when that happens I\'d like to set a query string that contains the item\'s Id so that if the user refreshes the page (or

相关标签:
1条回答
  • 2020-12-22 19:33

    In your $routeProvider configuration set reloadOnSearch to false:

    $routeProvider
      .when('/items', {
        controller: 'ItemsCtrl',
        templateUrl: '/templates/items',
        reloadOnSearch: false
      },
      ...
    );
    

    and in your controller use $location.search() to set the id param:

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