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.

app.run(['$route', '$rootScope', '$location', function ($route, $rootScope, $location) {
var original = $location.path;
$location.path = function (path, reload) {
if (reload === false) {
var lastRoute = $route.current;
var un = $rootScope.$on('$locationChangeSuccess', function () {
$route.current = lastRoute;
un();
});
}
return original.apply($location, [path]);
};
}])

  

There you go, now here is what it will look like in the controller where the path is being changed.

$location.path('/sample/' + $scope.checkinId, false);

  

Well, that’s all there is to it, we are now free to change path of the URL without reloading the page. If you have any questions, comments or suggestions feel free to leave a comment!

AngularJS Change Path Without Reloading的更多相关文章

  1. angularjs路由path方式实现原理探究

    angularjs路由 https://angular.io/guide/router 通过URL解释, 来定位客户端生成的浏览器端视图. 你可绑定路由到页面的链接上, 当用户点击链接, 可以浏览到相 ...

  2. Change visual studio 2015 enterprise installation path(转)

    I would like to install VS2015 in a drive different than C:. The problem is that when I run the inst ...

  3. werkzeug中reloader的实现

    在用flask开发时,如果把use_reloader设为True(debug设为True也能实现),那当你修改了app代码或调用环境发生改变时,服务器会自动重启,如下 * Detected chang ...

  4. zabbix 3.2 高可用实现方式二-pacemaker+corosync实现zabbix高可用集群

    一.pacemaker 是什么 1.pacemaker 简单说明 2.pacemaker 由来 二.pacemaker 特点 三.pacemaker 内部结构 1.群集组件说明: 2.功能概述 四.c ...

  5. Known BREAKING CHANGES from NH3.3.3.GA to 4.0.0

    Build 4.0.0.Alpha1 =============================   ** Known BREAKING CHANGES from NH3.3.3.GA to 4.0. ...

  6. git commit guidelines

    git-commit-guidelines AngularJS Development Setup Running Tests Coding Rules Commit Message Guidelin ...

  7. PHP开发调试环境配置(基于wampserver+Eclipse for PHP Developers )

    1 软件准 WampServer 下载地址:http://www.wampserver.com/en/#download-wrapper    我下的是 里面包含了搭建PHP必须的4个软件:   1. ...

  8. 使用ZooKeeper实现软负载均衡(原理)

    ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,提供的功能包括配置维护.名字服务.分布式同步.组服务等. ZooKeeper会维护一个树形的数据结构,类似于Windows资源管理器 ...

  9. JAVA设计模式《四》

    经过前几篇的介绍相信大家对JAVA的设计模式一定有所解了,本篇我们再一起学习一下适配器模式.代理模式和工厂模式. 适配器模式使用的场景非常多,例如现实生活中,我们的笔记本电脑的充电线大部分都是三向插头 ...

随机推荐

  1. Java虚拟机类型卸载和类型更新解析(转)

    转自:http://www.blogjava.net/zhuxing/archive/2008/07/24/217285.html [摘要]          前面系统讨论过java 类型加载(loa ...

  2. Swift——(三)Swift神奇的下划线

    在Swift在.有许多神奇的下划线,在这里,我们将看到神奇的汇总,我希望能够帮助其他很多学习Swift朋友. @Author: twlkyao转载或者引用请保留此行. 1.格式化数字字面量     通 ...

  3. SSH框架总结(帧分析+环境结构+示例源代码下载)

    首先,SSH不是一个框架.而是多个框架(struts+spring+hibernate)的集成,是眼下较流行的一种Web应用程序开源集成框架,用于构建灵活.易于扩展的多层Web应用程序. 集成SSH框 ...

  4. bnu 34986 Football on Table(数学+暴力)

    pid=34986" target="_blank" style="">题目连接:bnu 34986 Football on Table 题目大 ...

  5. MyEclipse10.0 集成 SVN

    一:下载服务端和client工具   服务端安装工具:Setup-Subversion-1.6.5.msi client安装工具:TortoiseSVN 下载地址:http://subclipse.t ...

  6. ASP.NET MVC+EF框架+EasyUI实现权限管理系列(19)-用户信息的修改和浏览

    原文:ASP.NET MVC+EF框架+EasyUI实现权限管理系列(19)-用户信息的修改和浏览  ASP.NET MVC+EF框架+EasyUI实现权限管系列 (开篇)   (1):框架搭建    ...

  7. vim温馨提示

    (一)各种文本操作 各种跳转 h,j,k,l h左移一个字符,j下移一行,k上移一行,l右移一个字符 w.b w 下一个单词,b上一个单词 0,$   行首,行尾 G,gg.30% 3G跳到第3行,g ...

  8. swift 注意事项 (十六) —— 可选链

    可选链(Optional Chaining) 我们都知道"可选型"是什么.那么可选链又是什么,举个样例解释一下: struct MyName{      var name } st ...

  9. Host和Server的开发

    Host和Server的开发 对于开发人员来说,代码就是最好的文档,如上一篇博文所说,下面我们就会基于Kanata项目的一些具体调用代码,来进一步深入理解OWIN的实现和作用. 今天我们先针对Host ...

  10. 防SQL注入:生成参数化的通用分页查询语句

    原文:防SQL注入:生成参数化的通用分页查询语句 前些时间看了玉开兄的“如此高效通用的分页存储过程是带有sql注入漏洞的”这篇文章,才突然想起某个项目也是使用了累似的通用分页存储过程.使用这种通用的存 ...