Umar Syal Umar Syal - 1 year ago 70
AngularJS Question

Execute Angular code no matter what route user lands on

what I'm trying to do is write a piece of code in angular which runs against all of the routes.

generally the behavior in angular is that if I have a controller for the root route, it will run only when I go to that route. But I don't want this behavior. I want a piece of code to run no matter if the starting route user entered is , , or any other valid route.

well I'll try to be more clear...some piece of code should run whenever the client app runs. no matter which route it starts from

any help would be very kind

Answer Source

You can use the run block. Run blocks are like main method if you take in Java or other languages. A run block is the code which needs to run to kickstart the application.

var app = angular.module('App', ['']); {
  //This will get execute after your config phase. 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download