AngularJS module: this versus $scope
This question already has an answer here:
The two implementations are used differently in the view. The this syntax is used together with the controller as syntax, which essentially makes your controller your view model.
controller as example
In Controller
this.text = "Controller as example"
In View
<div ng-controller="myCtrl as controllerViewModel">
{{controllerViewModel.text}}
</div>
Scope equivalent
In Controller
$scope.text = "Scope example";
In View
<div ng-controller="myCtrl">{{text}}</div>
Here are some usefull links regarding the subject
https://docs.angularjs.org/api/ng/directive/ngController
http://toddmotto.com/digging-into-angulars-controller-as-syntax/
https://thinkster.io/egghead/experimental-controller-as-syntax/
'this'指的是你的HelloCtrl的实例... $ scope是一个完全不同的对象,它已经得到状态,并通过角度进行管理
链接地址: http://www.djcxy.com/p/77806.html上一篇: 为什么我们在AngularJS中使用$ rootScope。$ broadcast?
下一篇: AngularJS模块:这与$范围