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. PolarDB PostgreSQL logindex 设计

    背景介绍 PolarDB采用了共享存储一写多读架构,读写节点RW和多个只读节点RO共享同一份存储,读写节点可以读写共享存储中的数据:只读节点仅能各自通过回放日志,从共享存储中读取数据,而不能写入,只读 ...

  2. P3175-[HAOI2015]按位或【min-max容斥,FWT】

    正题 题目链接:https://www.luogu.com.cn/problem/P3175 题目大意 开始有一个\(n\)位二进制数\(s=0\),每次有\(p_i\)概率选取数字\(i\)让\(s ...

  3. 从零开始部署 Yapi(Windows+Nginx)

    一.环境准备及安装 本文中是以本地 Windows 作为安装环境,Nginx 做反向代理,亲测验证可用. Yapi 运行需要的环境: Nodejs,MongoDB 安装包都在文档末尾处 1.1 安装 ...

  4. UE4技术总结——委托

    UE4技术总结--委托 目录 UE4技术总结--委托 一.定义 二.用法 2.1 声明与调用委托 2.1.1 单播委托 2.1.1.a 声明 2.1.1.b 绑定 2.1.1.c 执行委托 2.1.1 ...

  5. Go语言核心36讲(Go语言基础知识三)--学习笔记

    03 | 库源码文件 在我的定义中,库源码文件是不能被直接运行的源码文件,它仅用于存放程序实体,这些程序实体可以被其他代码使用(只要遵从 Go 语言规范的话). 这里的"其他代码" ...

  6. Java基础之(十一):方法

    Java方法详解 何谓方法(了解) System.out.println() // 类 对象 方法 方法是语句的集合,它们在一起执行一个功能. 方法是解决一类问题的步骤的有序集合 方法包含于类或对象中 ...

  7. 【c++ Prime 学习笔记】第12章 动态内存

    对象的生存期: 全局对象:程序启动时创建,程序结束时销毁 局部static对象:第一次使用前创建,程序结束时销毁 局部自动对象:定义时创建,离开定义所在程序块时销毁 动态对象:生存期由程序控制,在显式 ...

  8. Scrum Meeting 0425

    零.说明 日期:2021-4-25 任务:简要汇报两日内已完成任务,计划后两日完成任务 一.进度情况 组员 负责 两日内已完成的任务 后两日计划完成的任务 qsy PM&前端 完成登录.注册A ...

  9. js基础学习之"=="与"==="的区别

    var a = 1; var b = 1; var c = "1"; 1. "==" 可理解为相等运算符.相等运算符比较时,会自己进行类型转换,等于什么类型就会 ...

  10. Photoshop教程,视频MP4格式转换为GIF格式

    转自百度问题 https://zhidao.baidu.com/question/1497485136643778259.html Adobe PhotoShop软件的最bai新du本是可以编辑视zh ...