有兩種用于訪問控制器功能的模式: this和$scope。我應(yīng)該在何時使用?我了解this已設(shè)置為控制器,并且$scope是視圖范圍鏈中的一個對象。但是,通過新的“ Controller as Var”語法,您可以輕松使用其中一種。所以我要問的是什么是最好的,未來的方向是什么?例:使用 thisfunction UserCtrl() { this.bye = function() { alert('....'); };}<body ng-controller='UserCtrl as uCtrl'> <button ng-click='uCtrl.bye()'>bye</button>使用 $scopefunction UserCtrl($scope) { $scope.bye = function () { alert('....'); };}<body ng-controller='UserCtrl'> <button ng-click='bye()'>bye</button>我個人發(fā)現(xiàn),this.name與其他Java OO模式相比,它更容易上眼并且更自然。請教?angularjs
3 回答

一只甜甜圈
TA貢獻(xiàn)1836條經(jīng)驗 獲得超5個贊
$scope
在Angular 2.0中已被刪除。因此,this
隨著Angular 2.0的發(fā)布日期越來越近,使用將是其他人希望遵循的方法。
- 3 回答
- 0 關(guān)注
- 845 瀏覽
添加回答
舉報
0/150
提交
取消