Material: Checkbox ng-change issue

Created on 8 Oct 2015  路  5Comments  路  Source: angular/material

Using this code:

<div ng-repeat="option in question.options">
    <md-checkbox class="question-option" data-condition="{{question.condition}}" checklist-model="answers.answer[question.survey_question_id]" checklist-value="option.id" ng-change="check_condition(answers.answer[question.survey_question_id])" aria-label="{{question.question}}">{{option.option}}</md-checkbox>
</div>

The function is called with everychange, however, it returns the model that is before the action.
Lets say there are 2 checkboxes, both unchecked. If you check one of them, the model returns null, but if you uncheck it, it returns the checked value.

urgent

Most helpful comment

i've solved with this:

<md-checkbox ng-model="isCovered" ng-change="toggle(isCovered)">Description</md-checkbox>

And in the controller function i did this:

$scope.isCovered = false;
$scope.toggle = function(newValue){
    $scope.isCovered = newValue;
    //use value
}

All 5 comments

i think we have the same problem, ng-change doesn't provide the correct value of ng-model

I solved this by throttling the function. In my case, it was triggering twice.

i've solved with this:

<md-checkbox ng-model="isCovered" ng-change="toggle(isCovered)">Description</md-checkbox>

And in the controller function i did this:

$scope.isCovered = false;
$scope.toggle = function(newValue){
    $scope.isCovered = newValue;
    //use value
}

@anteksiler can you please provide a codepen of your problem?

This issue is closed as part of our 鈥楽urge Focus on Material 2' efforts.
For details, see our forum posting @ http://bit.ly/1UhZyWs.

Was this page helpful?
0 / 5 - 0 ratings