有两种用于访问控制器功能的模式:   this和$scope。
我应该在何时使用?我知道this已设置为控制器,并且$scope是视图范围链中的一个对象。但是使用新的“ Controller as Var”语法,您可以轻松使用其中任何一个。所以我要问的是什么是最好的,未来的方向是什么?
例:
- 使用 - this- function UserCtrl() { this.bye = function() { alert('....'); }; }- <body ng-controller='UserCtrl as uCtrl'> <button ng-click='uCtrl.bye()'>bye</button>
- 使用 - $scope- function UserCtrl($scope) { $scope.bye = function () { alert('....'); }; }- <body ng-controller='UserCtrl'> <button ng-click='bye()'>bye</button>
我个人发现,this.name与其他Java OO模式相比,它更容易上眼并且更自然。
请咨询?