Change route parameters without updating view

后端 未结 3 1762
温柔的废话
温柔的废话 2020-12-24 14:16

I\'m currently trying to figure out how to change the route parameters without reloading the entire page. For example, if I start at

http://www.example.com/#/page

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-24 14:26

    Ok, after a lot of searching. I answered my own question.

    I've discovered finding anything on the angular documentation is incredibly impossible, but sometimes, once it's found, it changes how you were thinking about your problem.

    I began here: http://docs.angularjs.org/api/ng.$location Which took me here: http://docs.angularjs.org/guide/dev_guide.services.$location Which took me to this question: AngularJS Paging with $location.path but no ngView reload

    What I ended up doing: I added $location.search({name: 'George'}); To where I wanted to change the name (A $scope.$watch).

    However, this will still reload the page, unless you do what is in that bottom StackOverflow link and add a parameter to the object you pass into $routeProvider.when. In my case, it looked like: $routeProvider.when('/page', {controller: 'MyCtrl', templateUrl:'path/to/template', reloadOnSearch:false}).

    I hope this saves someone else a headache.

提交回复
热议问题