HTML模板enableInput()獲取所有NG-重複按鍵觸發,當我在一個按鈕,點擊試圖觸發NG-重複按鈕的功能,但功能被觸發的所有NG-重複按鈕
<md-card ng-repeat="item in vm.feeCard | orderBy:'$index':true">
<div flex layout="column">
<div layout layout-align="space-between center">
<md-input-container >
<input name="feename" ng-model="item.name" placeholder="Fee Name" ng-readonly="vm.defaultReadonly" />
</md-input-container>
<md-input-container >
<input name="amount" ng-model="item.amount" placeholder="$ Amount" ng-readonly="vm.defaultReadonly" />
</md-input-container>
</div>
<md-button class="md-primary md-raised" ng-click="vm.enableEditing()">Edit</md-button> >these repeated buttons triggered when i click one of them
</div>
</md-card>
我的控制器
(函數(){ '使用嚴格'; 角 .module( 'app.admin') .controller( 'schoolFeeCtrl',schoolFeeCtrl);
schoolFeeCtrl.$inject = ['$mdSidenav', '$http', 'msUtils', 'commonVar', '$mdDialog'];
function schoolFeeCtrl($mdSidenav, $http, msUtils, commonVar, $mdDialog) {
var vm = this;
vm.title = 'schoolFeeCtrl';
vm.feeCard = [];
vm.defaultReadonly = true;
vm.chipsRemovable = false;
vm.enableEditing = function() {
vm.defaultReadonly = false;
vm.chipsRemovable = true;
};
}
})();
首先,我強烈建議您立即開始使用Angular4。我不確定這是否與AngularJS相同,但是在HTML文件中的Angular4中,您可以調用按鈕的函數並傳入$ event。從組件的ts文件中,您可以通過$ event.target訪問單個按鈕。現在你有了這個按鈕,你可以看看它是'id'屬性來告訴哪個按鈕被點擊了。 – ObjectiveTC