Form in AngularJS showing previously selected checkboxes

Posted By : Md Qasim Siddiqui | 04-Dec-2014

Hi guys, today I came across an issue related to checkboxes whenever I select some checkboxes and do not submit form ,instead I cancel the form and again opening of form , Checkboxes remains in same state .

 

Previousely I was using this code -




{{sample.name}}
 

And on cancel button I was calling cancelForm() action which sets the state of ng-model "q.sample" to false , but it was not helping me. So I googled and found solution . Instead of setting ng-model to q.sample, use the repeated sample and use a property on each one like this , ng-model="sample.checkState" My Complete Code




{{sample.name}}
 

And My js code on cancellation of form which set the checked values of all checkboxes to false

 $scope.cancelForm = function() {
    $scope.MyForm = false

    angular.forEach($scope.list, function(item) {
        item.checked = false;
    });
} 

Hope this will help you!

About Author

Author Image
Md Qasim Siddiqui

Qasim is an experienced web app developer with expertise in groovy and grails,Hadoop , Hive, Mahout, AngularJS and Spring frameworks. He likes to listen music in idle time and plays counter strike.

Request for Proposal

Name is required

Comment is required

Sending message..