How can we watch expressions inside the controller in angular 1.4 using angular -new-router

Since we cannot enter $scopeinside controllers in Angular 1.4+, how can we look at expressions the way we did with $scope.$watch?

An attempt to enter $scopecan be seen here (the error "Unable to create an instance of the controller"), and the textbooks indicate that:

Angular will not be able to instantiate the controller if we pass $ scope in this. It determines its observable properties. ( source )

+4
source share
3 answers

npm; , . npm, : npm install loomio-angular-router@0.5.7

: ng-viewport ng-outlet, .

+2

, ngNewRouter, . , .

, :

$ git clone git@github.com:angular/router.git
$ cd router
$ npm install
$ gulp angularify

dist

+2

you have $ watch in .activate. Check below (copy paste from my application).

function accountHistoryController (authService, accountFactory, CONSTANTS, $q, $routeParams) {

}
accountHistoryController.prototype.canActivate = function() {
    return !!this.authService.isAuthenticated();
}
accountHistoryController.prototype.activate = function($scope) {
    console.log ($scope);
    $scope.$watch('_this.currentPage', function(newPage){
    if (newPage == undefined) return;

});

}
+2
source

All Articles