问题描述
目前,我正在试图找出如何更改路由参数无需重新加载整个页面。例如,如果我开始在
I'm currently trying to figure out how to change the route parameters without reloading the entire page. For example, if I start at
但更新的名称是乔治,改变路线是:
but update a name to be 'George', to change the route to be:
如果我已经有了路由。
不重装的位置。可以只设置$ routeParams.name =乔治?
Without reloading the location. Can one just set $routeParams.name = "George" ?
编辑:
另外,有一个方法来更新无需重新加载或重置页面?
Alternatively, is there a way to update http://www.example.com/#/page?name=George without reloading or resetting the page?
推荐答案
好吧,很多搜索后。我回答我自己的问题。
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.
我开始在这里: $位置
这花了我在这里:http://docs.angularjs.org/guide/dev_guide.services.$location
这把我带到了这个问题:AngularJS寻呼与$ location.path但没有ngView重装
I began here: http://docs.angularjs.org/api/ng.$locationWhich took me here: http://docs.angularjs.org/guide/dev_guide.services.$locationWhich took me to this question: AngularJS Paging with $location.path but no ngView reload
我最终什么事做:
我加了 $ location.search({名称:'乔治'});
的地方,我想改名字(A $ $范围的手表。)
What I ended up doing:I added $location.search({name: 'George'});
To where I wanted to change the name (A $scope.$watch).
不过,这仍然会重新载入页面,除非你做的是在底部计算器链接和参数添加到您传递到 $ routeProvider.when
的对象。就我而言,它看起来像: $ routeProvider.when('/页',{控制器:'MyCtrl',templateUrl:'路径/要/模板',reloadOnSearch:假})
。
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.
这篇关于更改路由参数,而不更新视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!