angularjs - Run a function every time an angular route is navigated to -


i want run function every time angular route navigated to.

one option add myfunction() top of every controller. seems repetitive. there better way run myfunction() every time $location changes?

if using ui-router, can bind function $rootscope. see statechange section: https://github.com/angular-ui/ui-router/wiki#state-change-events

    $rootscope.$on('$statechangesuccess',      function(event, tostate, toparams, fromstate, fromparams){ ... }) 

Comments