2

I need to call couple of JavaScript functions (placeholder fallback etc) on AngularJS view change. How can I achieve this globally?

2 Answers 2

3

You can listen for the route change success event and call the functions inside the callback:

$scope.$on('$routeChangeSuccess', function(next, current) { 
   // call your functions here
 });
Sign up to request clarification or add additional context in comments.

Comments

0

Instead of adding the following $scope.on you can also add a custom function using ng-init when the controller is called (new view state).

HTML:

<div class="container-fluid" ng-controller="home-services" ng-init="init()"> 
  --- Code ---
</div>

ANGULARJS:

angular.module('home').controller('home-services', function($scope){
  $scope.init = function(){

  ---- Your Javascript ----

  };
});

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.