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. 【Hibernate步步】--一对一映射双向关联具体解释(两)

    很抱歉.有两天没更新博客文章,不要写文章一天真的感觉很是空的啊.制定一个写作习惯,想改也改不掉啊.说点题外话,前两天我收到一封私人信件给朋友,我写邀请函的文章OWS文章.一种技术用于研究图标工具,这位 ...

  2. iOS学习笔记---简单的学习总结

    1.xcode6.0官方的版本必须是OS X10.9.4而以上的版本安装前: 2,xcode6.0正式版创建命令行项目时,无法选择swift语言:可是创建iOS应用项目时能够选择swift语言. 3, ...

  3. 持续集成并不能消除 Bug,而是让它们非常容易发现和改正(转)

    互联网软件的开发和发布,已经形成了一套标准流程,最重要的组成部分就是持续集成(Continuous integration,简称 CI). 本文简要介绍持续集成的概念和做法. 一.概念 持续集成指的是 ...

  4. XStream 用法汇总

            XStream是一家Java对象和XML转换工具,很好很强大.它提供了所有的基本型.排列.收集和其他类型的支持,直接转换.因此XML在数据交换经常使用.对象序列化(和Java对象的序列 ...

  5. Git 命令速查表

    Git 命令速查表 1.常用的Git命令 命令 简要说明 git add 添加至暂存区 git add-interactive 交互式添加 git apply 应用补丁 git am 应用邮件格式补丁 ...

  6. SharePoint 2013 如何使用Silverlight

    1.打开VS,创建一个Silverlight计划.例如下面的附图: 2.配置选择默认的,当然也能够不勾选Host Application,例如以下图: 3.加入Silverlight控件,2个labe ...

  7. 一个非常不错的gridview 风格

    <style type="text/css"> <!-- .datable {background-color: #9FD6FF; color:#333333;  ...

  8. Oracle 使用

    Oracle 日志文件 摘要: 本篇博文呢主要是介绍 Oracle 日志文件的管理, 对 Oracle 日志文件呢,有两个比较关键的名词, 即日志文件组 LogFileGroup 和日志文件 LogF ...

  9. CSDN下载频道2014年11月4日本-5日常维护公告

    尊敬的用户: CSDN于2005年推出了下载服务.经过数年的发展.下载频道的用户已经为无数用户提供了帮助,分享500万的技术资源. CSDN下载频道将于2014年11月4日23点至11月5日8点进行积 ...

  10. 浅谈JavaScript中typeof与instanceof的区别

      首先,我们从其常规定义入手:       instanceof 运算符可以用来判断某个构造函数的 prototype 属性是否存在另外一个要检测对象的原型链上.(需要注意的一点是:prototyp ...