Reputation: 436
I have list of groups and generate that group list in HTML with ng-repeat
(list of buttons) and its working perfectly. But in case when i am trying to disable some buttons with ng-disabled
by call function to check the value, i just amazed my loop and buttons showing correctly but ng-disable="myfunc()"
called many times.
My Code:
<button class="button button-block button-calm btn-shape" ng-click="startSurvey(group.survey_id,group.id)" ng-repeat="group in groupList" ng-disabled="checkGroupCompleted($index)">
{{group.title}}
</button>
Group List:
Controller:
$scope.checkGroupCompleted = function(groupID){
console.log(groupID);
}
Console Output:
I just need similar functionality: JSFiddle
Upvotes: 1
Views: 1836
Reputation: 7739
This is what angular is all about. Whenever your $scope
will get modified each time digest
cycle will run so each and every function is going to be called.
In case of ng-show
, ng-show
, ng-disabled
etc same process it follows.
Upvotes: 1
Reputation: 830
You are use ng-repeat in button it self so when loop start function it self fire many time so you can put ng-repeat to its parent element and then after put button inside after that you add ng-disabled to button and check it.
For ex.
<div> ng-repeat=groups in group> <button> ng-disabled="checkGroupCompleted($index)"></button> </div> $scope.checkGroupCompleted = function(groupID){ return (groupID === 1); }
Upvotes: 0
Reputation: 41
$scope.checkGroupCompleted = function(groupID) {
return (groupID === 1);
}
if the value is 1 it will return true or else false
Upvotes: 0