Friday, 15 January 2010

javascript - Angularjs - refresh controller scope on route change -



javascript - Angularjs - refresh controller scope on route change -

was wondering best way refresh controller scope on route change?

any help appreciated!

i refactor have initialisation of info properties on scope in single function, called initscope() called when controller first run, , on $routechangesuccess (and $routechangeupdate if want handle changes url resolve same route) event(s).

e.g.

app.controller('myctrl', ['$scope', function ($scope) { function initscope() { $scope.foo = 1; $scope.bar = { ram: 'ewe' }; } initscope(); $scope.$on('$routechangeupdate', initscope); $scope.$on('$routechangesuccess', initscope); }

javascript angularjs

No comments:

Post a Comment