In this video we will discuss
1. Different events that are triggered when a route change occurs in an angular application
2. Logging the events and event handler parameters to inspect their respective properties 

When route navigation occurs in an Angular application, the following events are triggered
1. $locationChangeStart
2. $routeChangeStart
3. $locationChangeSuccess
4. $routeChangeSuccess 

The following code proves the above point

.controller("studentsController", function ($http, $route, $rootScope, $log) {
    var vm = this;
 
    $rootScope.$on("$locationChangeStart", function () {
        $log.debug("$locationChangeStart fired");
    });
 
    $rootScope.$on("$routeChangeStart", function () {
        $log.debug("$routeChangeStart fired");
    });
 
    $rootScope.$on("$locationChangeSuccess", function () {
        $log.debug("$locationChangeSuccess fired");
    });
 
    $rootScope.$on("$routeChangeSuccess", function () {
        $log.debug("$routeChangeSuccess fired");
    });
 
    vm.reloadData = function () {
        $route.reload();
    }
 
    $http.get("StudentService.asmx/GetAllStudents")
                .then(function (response) {
                    vm.students = response.data;
                })
})

Please note that we are injecting $log service into the controller function to log the events. 

In our previous video, we used $$route.originalPath property to get the route that the user is navigating to. How do we know next parameter has $$route.originalPath property. Well the easiest way is to log and inspect their properties. The following code does exactly the same thing.

.controller("studentsController", function ($http, $route, $scope, $log) {
    var vm = this;
 
    $scope.$on("$routeChangeStart", function (event, next, current) {
        $log.debug("RouteChangeStart Event");
        $log.debug(event);
        $log.debug(next);
        $log.debug(current);
    });
 
    $scope.$on("$locationChangeStart", function (event, next, current) {
        $log.debug("LocationChangeStart Event");
        $log.debug(event);
        $log.debug(next);
        $log.debug(current);
    });
 
    vm.reloadData = function () {
        $route.reload();
    }
 
    $http.get("StudentService.asmx/GetAllStudents")
                .then(function (response) {
                    vm.students = response.data;
                })
})

In this example we have logged just $routeChangeStart & $locationChangeStart events parameters. In a similar way, you can also log $routeChangeSuccess & $locationChangeSuccess events parameters.

Now, launch the browser developer tools and you can see the properties available

Part 39 AngularJS route change events的更多相关文章

  1. 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 ...

  2. [AngularJS] Accessible Button Events

    Often buttons need to be handled by JavaScript, and if done improperly it can lead to accessibility ...

  3. [Redux] Fetching Data on Route Change

    We will learn how to fire up an async request when the route changes. A mock server data: /** /api/i ...

  4. part 36 AngularJS route reload

    In this video we will discuss angular route service reload() method. This method is useful when you ...

  5. Cisco IOS debug command reference Command A through D

    debug aaa accounting through debug auto-config debug aaa accounting : to display information on acco ...

  6. AngularCSS--关于angularjs动态加载css文件的方法(仅供参考)

    AngularCSS CSS on-demand for AngularJS Optimize the presentation layer of your single-page apps by d ...

  7. AngularJs ng-route路由详解

    本篇基于ng-route来讲下路由的使用...其实主要是 $routeProvider 搭配 ng-view 实现. ng-view的实现原理,基本就是根据路由的切换,动态编译html模板. 更多内容 ...

  8. [AngularJS] ngModelController render function

    ModelValue and ViewValue: $viewValue: Actual string value in the view. $modelValue: The value in the ...

  9. [RxJS + AngularJS] Sync Requests with RxJS and Angular

    When you implement a search bar, the user can make several different queries in a row. With a Promis ...

随机推荐

  1. 国庆总结:echarts自定义颜色主题,保证你看的明明白白

    为什么需要使用颜色主题 随着用户审美越来越高,不再是过去那样只注重功能. 所以对界面的颜色样式都具有一定的审美要求 此时颜色是否好看就非常重要了 因为人都是视觉动物 对界面的第一印象肯定都是颜色. 如 ...

  2. 常见的==和equals比较

    在笔试上碰到很多这样类似的题,全部整理到这里 String a = "Hello"; String b = "Hello"; String c = new St ...

  3. Node.js Koa框架学习笔记

    Koa 基本介绍 Koa是Node.js中非常出名的一款WEB框架,其特点是短小精悍性能强. 它由Express原版人马打造,同时也是Egg框架的设计蓝图,可以说Koa框架的学习性价比是非常高的. 官 ...

  4. 一个简单的单例模式Demo

    /** * @author :nx014924 * @date :Created in 5/30/2021 1:09 PM * @description: * @modified By: * @ver ...

  5. 无网环境安装docker之--rpm

    总体思路:找一台可以联网的linux,下载docker的RPM依赖包而不进行安装(yum localinstall),将所有依赖的rpm环境打包好,再在无网环境中解压逐一安装(rpm:  --forc ...

  6. SpringCloud 2020.0.4 系列之Eureka

    1. 概述 老话说的好:遇见困难,首先要做的是积极的想解决办法,而不是先去泄气.抱怨或生气. 言归正传,微服务是当今非常流行的一种架构方式,其中 SpringCloud 是我们常用的一种微服务框架. ...

  7. OO_JAVA_电梯运行模拟_单元总结

    电梯运行模拟--三次作业总结 目录 电梯运行模拟--三次作业总结 总体遵循的设计思路 逻辑解耦 电梯与调度器解耦 楼层信息的存储和变更与电梯.调度器解耦 调度器运行流程解耦 第一次电梯,蠢笨串行先到先 ...

  8. find&正则表达式

    标准的正则表示式格式 常用元字符 代码 说明 . 匹配除换行符以外的任意字符 \w 匹配字母或数字或下划线 \s 匹配任意的空白符 \d 匹配数字 \b 匹配单词的开始或结束 ^ 匹配字符串的开始 $ ...

  9. C++学习笔记之pimpl用法详解

    原文链接:https://www.jb51.net/article/122557.htm 在编写稳定代码是,管理好代码间的依赖性是不可缺少的一个环节.特别是库文件的编写中,减少代码间的依赖性可以提供一 ...

  10. 最大连续数列和 牛客网 程序员面试金典 C++ Python

    最大连续数列和 牛客网 程序员面试金典 C++ Python 题目描述 对于一个有正有负的整数数组,请找出总和最大的连续数列. 给定一个int数组A和数组大小n,请返回最大的连续数列的和.保证n的大小 ...