码迷,mamicode.com
首页 > Web开发 > 详细

AngularJS Change Path Without Reloading

时间:2014-10-13 17:49:19      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   os   ar   java   sp   div   art   

To change path URL with AngularJS, $location.path() is passed the new URL as a parameter, and the page is automatically reloaded. This means that if you ever make a change to the URL in an Angular application, then the partial and controller will be reloaded automatically. This is great most of the time, however, there are times when reloading the controller is unwanted. AngularJS doesn’t have a native fix to stop reloading when the path is changed. So a quick addition to our app.js file will do the trick.

Solution

The solution is essentially to add an extra parameter to $location.path(). So rather than just taking in the new URL, it will also take in a boolean were true will refresh the page and false will not. The following block of code is what needs to be added to the app.js file. 

AngularJS Change Path Without Reloading

标签:style   blog   io   os   ar   java   sp   div   art   

原文地址:http://www.cnblogs.com/jmtbai/p/4022113.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!