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. C++ Regsvr32订购具体解释

    一.Regsvr32命令 Regsvr 32命令是Windows在控制文件(如延长DLL.OCX.CPL文件)注册和反注册工具. 命令格公式:Regsvr32 [/s] [/n] [/i[:cmdli ...

  2. 使用Mockito进行单元测试【2】—— stub 和 高级特性[转]

    一篇中介绍了Mockito的基本信息,现在接着介绍Mockito强大的stub功能 2. Mockito使用实例 5. 对连续的调用进行不同的返回 (iterator-style stubbing) ...

  3. validateRequest="false"属性及xss攻击

    validateRequest="false"   指是否要IIS验证页面提交的非法字符,比如:>,<号等,当我们需要将一定格式得html代码获得,插入数据库时候,就要 ...

  4. JBPM——MyEclipse开发环境的搭建

    第一次接触JBPM我不知道如何在工程中的应用.查了一些资料.大约在JBPM随着时代的发展有一定的了解.首先JBPM它是JBoss件平台的一个组成部分.是一个灵活的,易扩展的工作流管理系统,仅仅只是这个 ...

  5. javascript、jQuery的扩展方法,扩展实例展示代码

    $(function () {    var total = 0, height = $(window).height(), memberScroll, cartScroll, proScroll;  ...

  6. flex builder 4.7 ios 该溶液无法找到设备

    行政建议,没有设备 1) 视图itunes 该服务正在启动(Bonjour服务).测试..... .即使没有这样的假设 2)"D:\Program Files\Adobe\Adobe Fla ...

  7. Flex 日志管理

    在Flex中调试方法有两种: 一是用trace()函数,在flex builder中进行调试: 二是用logTarget类,例如以下代码: // Create a target. var logTar ...

  8. 随记一个C的时间加减

    //Centos6 x86_64 #include <time.h>#include <stdio.h>#include <string.h>#include &l ...

  9. BZOJ 2120 色彩数 暴力

    标题效果:给定一个序列,两种操作: 1.询[l,r]间隔多少个不同的号码 2.单点变化 n,m<=1W 树盖树?树董事长?因此不必! 暴力之前,这个问题2s,不想复杂!适当的水太! 离散化一下! ...

  10. RethinkDB创始人教你如何打造一个伟大的互联网产品

    关于作者 我叫Slava Akhmechet,本人是 RethinkDB 的创始人之一,RethinkDB是开源,分布式数据库,旨在帮助开发人员与运营商在打造实时应用时处理无结构数据 如何打造一个伟大 ...