在Angularjs中this的指當前的scope。html
<a class=" ng-click="remove(this)"></a> <!--this指的是a標籤做用域下的scope--> <script> app.controller('myCtrl',function($scope){ $scope.remove = function (scope) { scope.remove(); }; }); </script>
來自知乎的解釋,https://www.zhihu.com/question/35780175app
<div ng-click="change()">{{value}}</div>
$scope.change = function(){ this.value = 'new value'; //等價於$scope.value = 'new value' }
<div ng-click="change()" ng-repeat="item in items">{{item.value}}</div>
$scope.change = function(){ this.item.value = 'new value'; //因爲是ng-repeat出來的,因此這裏this指向的scope是上面那個案例中$scope的子集。 //即this.$parent === $scope; }