1

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:

enter image description here

Controller:

$scope.checkGroupCompleted = function(groupID){
        console.log(groupID);

    }

Console Output:

enter image description here

I just need similar functionality: JSFiddle

3
  • 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. Commented Mar 24, 2017 at 11:04
  • hmm...ohk got it.. thanks :) Commented Mar 24, 2017 at 11:07
  • I think its because your function is not returning anything. It needs to return true for enabled and false for disabled. Commented Mar 24, 2017 at 11:08

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0
$scope.checkGroupCompleted = function(groupID) {
    return (groupID === 1);
}

if the value is 1 it will return true or else false

Comments

0

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);
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.