samedi 25 février 2017

How to select check boxes on load page

I am trying to select some of these check boxes on load. I need to be able to select and unselect all check boxes after the page is loaded. So far I tried :$scope.itemSelected = [{ "ItemID": 1, "ItemName": "Item 1" }];

        div ng-repeat="item in itemItems">
            <md-checkbox ng-checked="existsItem(item, itemSelected);" ng-click="toggleItem(item, itemSelected);" value="">
                
            </md-checkbox>
        </div>

angular.module('MyApp', ['ngMaterial'])
.controller('AdminController', function ($scope) {

$scope.itemItems = [{ "ItemID": 1, "ItemName": "Item 1" }, { "ItemID": 2, "ItemName": "Item 2" },
    { "ItemID": 3, "ItemName": "Item 3" }, { "ItemID": 4, "ItemName": "Item 4" },
    { "ItemID": 5, "ItemName": "Item 5" }];
$scope.itemSelected = [];

$scope.toggleItem = function (item, list) {
    var idx = list.indexOf(item);
    if (idx > -1) {
        list.splice(idx, 1);
    }
    else {
        list.push(item);
    }
};

$scope.existsItem = function (item, list) {
    return list.indexOf(item) > -1;
};
})




Aucun commentaire:

Enregistrer un commentaire