jeudi 2 juillet 2015

How to get checked checkbox value and store it array variable in angularjs?

I have created array list and listing it as multiple check box. From that if i select i'm storing into the array variable and if I uncheck its need to be remove from array. I tried this is working for but while uncheck value is not removing from the array variable.

Here is my code below and jsfiddle

HTML

    <div ng-app="myApp" ng-controller="MyCtrl">
        <lable ng-repeat="list in lists">
        <input type="checkbox" name="chk[]" ng-model="lst" value="{{list.vl}}" ng-change="change()">
        {{list.vl}} <br>
        </lable>
    </div>

SCRIPT

    var myApp = angular.module('myApp', []);

    myApp.controller('MyApp', function($scope){
        $scope.list = [
            {'vl' : 1},
            {'vl' : 2},
            {'vl' : 3},
            {'vl' : 4},
            {'vl' : 5},
        ];

        $scope.lst = {};
        $scope.change = function(){
            console.log($scope.lst);
        };
    });




Aucun commentaire:

Enregistrer un commentaire