I have a components controller and in order to use this inside local functions I have to declare a local var.
Is there a better way to bind to "this" inside new angular router? For example this function:
function appController ($router, $scope, $location, authService, $scope, $timeout) {
this.authService = authService;
this.pageTitle = "title";
_this = this;
//when location changes does some stuff
$scope.$on('$locationChangeSuccess', function (event, newLoc, oldLoc){
//hides the notifier
_this.accountCollapse = false;
_this.pageTitle = $location.path();
});
}
Is there another way to do it? Faster/better?
I think this way is the fastest. But you must declare variable
_this
with operator var to prevent some errors in the futureAnother option will be to bind
this
to listener like that: