I have used ng-init="isauthorised()" in my code to get call function after changing every URL
it call when page get refresh but I need this function to get call afer every click on ancher tag
I have used ng-init="isauthorised()" in my code to get call function after changing every URL
it call when page get refresh but I need this function to get call afer every click on ancher tag
One of the best things to do is to use the route provider to call a function before the page change happens. One example of this (modified from here) is:
$scope.$on('$locationChangeStart', function(event) {
// call your method here
});
The nice thing about this is you know your routine is going to get called and you don't have to modify the code for every anchor tag on the page. By the way, if you are interested in more information check the angular documentation here.
In your application if you want to trigger the function whenever the route changes,Below codes will use
$scope.$on('$routeChangeStart', function(next, current) {
... This Function will trigger when route changes ...
});
$scope.$on('$routeChangeSuccess', function(next, current) {
... This Function will trigger After the route is successfully changed ...
});
if you want to trigger the function, for particular routes, you give it in resolve functions in app.config
for example
myapp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/login', {
templateUrl: 'views/login.html',
controller: 'LoginCtrl'
}).
when('/home', {
templateUrl: 'views/home.html',
controller: 'HomeCtrl',
resolve: {
token: function(Token){
... Trigger the function what u want, and give token as dependency for particular route controller ...
}
}
}).
otherwise({
redirectTo: 'index.html'
});
}]
);