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. P1791-[国家集训队]人员雇佣【最大权闭合图】

    正题 题目链接:https://www.luogu.com.cn/problem/P1791 题目大意 有\(n\)个人,雇佣第\(i\)个需要\(A_i\)的费用,对于\(E_{i,j}\)表示如果 ...

  2. mqtt网关服务器连接阿里云关联物模型

    mqtt网关服务器连接阿里云关联物模型 卓岚专门为工业环境设计的RS485设备数据采集器/物联网网关,兼具串口服务器.Modbus网关.MQTT网关.RS485转JSON等多种功能于一体. 可以连接阿 ...

  3. Python3入门系列之-----内置的文件操作模块OS

    前言 在自动化测试中,经常需要查找操作文件,比如说查找配置文件(从而读取配置文件的信息),查找测试报告(从而发送测试报告邮件),经常要对大量文件和大量路径进行操作,这个时候就需要用到os模块. 使用前 ...

  4. windows terminal+wsl+neovim配置过程杂记

    长期记录,草稿 coc依赖于node,直接sudo apt intsll node得到的版本是10.x,无法满足要求, 这篇博客介绍了安装新版node的方法https://www.cnblogs.co ...

  5. VmWare装Linux&Centos步骤

    昨晚一次偶然的机会进入飞哥的直播间,他正在将用虚拟机搭建Linux环境的步骤,自己之前也确实安装过一次,不过没什么系统性总结,过程中有些步骤还需百度查找.于是乎今天决定从零基础在过一遍流程,便是这篇博 ...

  6. 【vue】获取异步加载后的数据

    异步请求的数据,对它做一些处理,需要怎么做呢?? axios 异步请求数据,得到返回的数据, 赋值给变量 info .如果要对 info 的数据做一些处理后再赋值给 hobby ,直接在 axios ...

  7. CSP初赛考点汇总

    qwq 为SCP初赛选手(我)收集的各种定理qwq 更新: 1.为了初赛都能用,不限于定理了 2.主旨为在短时间内复习各算法,备初赛 3.请确定你学习(学懂了)了 \(\texttt{oi}\) 的基 ...

  8. oracle dg failover灾难切换

    oracle dg failover灾难切换SQL> alter database recover managed standby database finish force;SQL> a ...

  9. Java基础之(二):Notepad++实现HelloWorld

    现在我们开始编写我们的第一个程序:Hello World! HelloWorld 新建一个java文件 文件后缀名为.java Hello.java 代码分析: 接下来写完最大的框之后,那接下来当然就 ...

  10. 使用nexus搭建一个docker私服

    使用nexus搭建docker私服 一.需求: 二.实现步骤 1.编写`docker-compose`文件,实现`nexus`的部署 2.修改/usr/lib/systemd/system/docke ...