user8587181
user8587181

Reputation:

how to show checked checkboxes first and after that unchecked in angularjs

I am fetching some records which are already assigned to users with checked checkboxes. I want to assign some additional ones that are coming as unchecked checkboxes. How can I show checked checkboxes first and then show whatever is unchecked after them?

Upvotes: 0

Views: 494

Answers (1)

Raghav
Raghav

Reputation: 1229

You can use angular filters to show checked checkboxes first and whatever is unchecked, show it after them

try this:

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.data = [
    {id: 1, value: 1},
    {id: 2, value: 0},
    {id: 3, value: 1},
    {id: 4, value: 0},
    {id: 5, value: 0}
  ];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<div ng-app="myApp">
<div ng-controller="myCtrl">
<h2>Checked</h2>
<div ng-repeat="item in data | filter : { value : 1}">
	{{item.id}} : <input type="checkbox" ng-checked="item.value=='1'"/>
</div>
<h2>Unchecked</h2>
<div ng-repeat="item in data | filter : { value : 0}">
	{{item.id}} : <input type="checkbox" ng-checked="item.value=='1'"/>
</div>
</div>
</div>

Hope it helps..

Upvotes: 1

Related Questions