Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
It is more desirable - scope, because not always directives will be able to have access to the controller.
And to scope - always.
Least
var self = this;
this.a = function() {
self.b = 'c';
} // или .bind(this)
// vs
$scope.a = function() {
$scope.b = 'c';
}
Personally, I use this. The main advantage is the ability to use Controller as Sintax. Which makes html much clearer.
<div ng-contoller="parentController">
<div ng-contoller="childController">
<!--Невозможно понять в каком контроллере находиться test-->
{{test}}
</div>
</div>
<div ng-contoller="parentController as parent">
<div ng-contoller="childController as child">
<!--Видно откуда вызывается test-->
{{parent.test}}
</div>
</div>
I use both: this for direct access to controller instances (see TekVanDo 's answer above), and $scope otherwise.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question