有兩種用于訪問控制器功能的模式: this和$scope。我應該在何時使用?我了解this已設置為控制器,并且$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>我個人發現,this.name與其他Java OO模式相比,它更容易上眼并且更自然。請教?angularjs
- 3 回答
- 0 關注
- 830 瀏覽
添加回答
舉報
0/150
提交
取消