2

I am using angular 1.5 component router in my application. Is there a way to detect route change in component router. I want to run some code on route change.

0

2 Answers 2

3

Sajeetharan s' answer is correct but its only for current scope.If you want it for every state change add it like this

run.$inject = ['$rootScope', '$location', '$cookieStore', '$http']; function run($rootScope, $location, $cookieStore, $http) { $rootScope.$on('$locationChangeStart', function(event, next, current) { console.log($location.path()); }); } app.run(run); 
Sign up to request clarification or add additional context in comments.

Comments

3

You can do with this piece of code,

$scope.$on('$locationChangeStart', function(event) { //add your logic }); 

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.