In this video we will discuss angular route service reload() method. This method is useful when you want to reload just the current route instead of the entire app. Let us understand this with an example. 

We will continue with the same example that we have been working with in the previous videos. When we navigate to http://localhost/students we see the list of students. Notice that when you click on the same students link, nothing happens. This means if we insert a new record in the database table and issue a request to the same route, you may not see the new records. 

One of the ways to see the new data is by clicking on the browser refresh button. The downside of this is that the entire app is reloaded. This means all the resources required to run your app will be reloaded. You can see all the resource requests made on the network tab in the browser developer tools. 

The other way is to reload just the current route. Here are the steps. 

Step 1 : Modify the studentsController function in script.js

.controller("studentsController", function ($http, $route) {
    var vm = this;
 
    vm.reloadData = function () {
        $route.reload();
    }
 
    $http.get("StudentService.asmx/GetAllStudents")
                .then(function (response) {
                    vm.students = response.data;
                })
})

Please note : 
1. $route service in injected in the controller function
2. reloadData() function is attached to the view model (vm) which will be available for the view to call. This method simply calls reload() method of the route service. 

Step 2 : Modify the partial template (students.html). Please note that we have included a button which calls reloadData() method when clicked.

<h1>List of Students</h1>
<ul>
    <li ng-repeat="student in studentsCtrl.students">
        <a href="students/{{student.id}}">
            {{student.name}}
        </a>
    </li>
</ul>
<button ng-click="studentsCtrl.reloadData()">Reload</button>

At this point
1. Run the app
2. Navigate to http://localhost/students. You should see list of students.
3. Insert a new record in the database table
4. Open browser developer tools
5. Click the Reload button 

There are 2 things to notice here
1. The newly added record will be shown on the view
2. Only the resources required to reload the current route are requested from the server

part 36 AngularJS route reload的更多相关文章

  1. Part 39 AngularJS route change events

    In this video we will discuss1. Different events that are triggered when a route change occurs in an ...

  2. AngularJs: Reload page

    <a ng-click="reloadRoute()" class="navbar-brand" title="home" data- ...

  3. Part 38 AngularJS cancel route change

    n this video we will discuss, how to cancel route change in Angular with an example. This is extreme ...

  4. 【经验】AngularJS

    1.关于ng-model <textarea id="feature_name" class="col-sm-3" placeholder="软 ...

  5. ngRoute AngularJs自带的路由

    ngRoute $routeProvider 配置路由的时候使用. 方法: when(path,route); 在$route服务里添加一个新的路由. path:该路由的路径. route:路由映射信 ...

  6. AngularJS路由系列(2)--刷新、查看路由,路由事件和URL格式,获取路由参数,路由的Resolve

    本系列探寻AngularJS的路由机制,在WebStorm下开发.主要包括: ● 刷新路由● 查看当前路由以及所有路由● 路由触发事件● 获取路由参数 ● 路由的resolve属性● 路由URL格式 ...

  7. angularjs路由菜单强制刷新

    在开发过程中遇到使用路由控制单页加载页面时,点击菜单页面不重新刷新的情况,angularjs认为路由没有变化,而不会去刷新页面,解决办法: angular.module('myApp').direct ...

  8. [译]用AngularJS构建大型ASP.NET单页应用(一)

    原文地址:http://www.codeproject.com/Articles/808213/Developing-a-Large-Scale-Application-with-a-Single 渣 ...

  9. AngularJS 基础

    1. AngularJs 是一个JS 框架,是一种基于MVC的设计模式 2. script 需引用 <script src="angular.min.js">,安装包 ...

随机推荐

  1. IdentityServer4[2]:启动一个新的IdentityServer项目

    启动一个新的IdentityServer项目 从头开始,从基础开始,然后变得更加复杂,循序渐进的学习 工具:VS2017 15.9.8 .Net Core2.2 基本过程 创建一个新的ASP.NET ...

  2. JVM类加载器的分类

    类加载器的分类 JVM支持两种类型的类加载器,分别为引导类加载器(Bootstrap ClassLoader)和自定义类加载器(User-Defined ClassLoader). 从概念上来讲,自定 ...

  3. 宝塔配置vnc+wine实现Q群机器人

    图形界面必备X Window System yum -y groupinstall "X Window System" 安装epel源 yum -y install epel-re ...

  4. postgresql高可用集群部署

    一.概况 1.概念 pgsql高可用集群采用postgresql+etcd+patroni+haproxy+keepalived等软件实现,以postgresql做数据库,etcd存储集群状态,pat ...

  5. 2021record

    2021-10-14 P2577 [ZJOI2004]午餐 2021-10-13 CF815C Karen and Supermarket(小小紫题,可笑可笑) P6748 『MdOI R3』Fall ...

  6. 听说,99% 的 Go 程序员都被 defer 坑过

    原文链接: 听说,99% 的 Go 程序员都被 defer 坑过 先声明:我被坑过. 之前写 Go 专栏时,写过一篇文章:Go 专栏|错误处理:defer,panic 和 recover.有小伙伴留言 ...

  7. Vim 不区分大小写

    Vim 不区分大小写 忽略:set ignorecase 恢复:set noignorecase

  8. Golang通脉之流程控制

    流程控制是每种编程语言控制逻辑走向和执行次序的重要部分,流程控制可以说是一门语言的"经脉". Go语言中最常用的流程控制有if和for,而switch和goto主要是为了简化代码. ...

  9. 时间轮机制在Redisson分布式锁中的实际应用以及时间轮源码分析

    本篇文章主要基于Redisson中实现的分布式锁机制继续进行展开,分析Redisson中的时间轮机制. 在前面分析的Redisson的分布式锁实现中,有一个Watch Dog机制来对锁键进行续约,代码 ...

  10. CQL和SQL的CRUD操作比较

    数据进行CRUD操作时,CQL语句和SQL语句的异同之处. 1.建表 2.CRUD语句比较 3.总结 1.建表 在此之前先分别创建两张表,插入数据,用来测试然后进行比较 在SQL数据库里面创建表 在C ...