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 -
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
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!
More From Oodles
Ready to innovate? Let's get in touch
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
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.