Tuesday, 11 April 2017

What are different route change events ?


While navigating the routes, below events are triggered : 
  • $routeChangeStart
  • $routeChangeSuccess
  • $locationChangeStart
  • $locationChangeSuccess

app.controller("studentController", function ($route, $http, $rootScope, $log) {
   $rootScope.$on("$locationChangeStart",
function () {
       $log.debug("$locationChangeStart triggered...");
   })
 
   $rootScope.$on("$routeChangeStart", function () {
       $log.debug("$routeChangeStart triggered...");
   })
 

   $rootScope.$on("$locationChangeSuccess", function () {
       $log.debug("$locationChangeSuccess triggered...");
   })
 
   $rootScope.$on("$routeChangeSuccess", function () {
       $log.debug("$routeChangeSuccess triggered...");
   })

   var curr = this;
   curr.reloadData = function() {
      $route.reload();
   }

   $http.get("service/api/GetAllStudents").then(
     function(response) {
        curr.students = response.data
;
     }

   )
});



Output
$routeChangeStart triggered...
$locationChangeStart triggered...
$locationChangeSuccess triggered...
$routeChangeSuccess triggered...

No comments:

Post a Comment

Note: only a member of this blog may post a comment.