vendredi 28 avril 2017

Angularjs: checkbox and ng-change

I have problems to understand how ng-change works. I have a list of user to invite to join an auction. I want to do this with a checkbox. If the user is checked, his name has to be saved into an array. And later i will invite them(i just know how to do this). But i don't understand how to use the checkbox. I did something like this:

        <ul class="list-group" ng-repeat="user in users">
           <li class="list-group-item" ng-hide="user.name == profile">
              <img ng-src="" class="image2" >
              <div class="username"> </div>
              <div class="userrole">  </div>
              <div class="usercompany"></div>
              <input type="checkbox"  ng-model="isChecked" ng-change="insertinvited(user.name)">

           </li>
       </ul>

And in my controller:

         $scope.invited = [];
$scope.insertinvited= function (name) {

    if($scope.isChecked){
        $scope.invited.push(name)
    }
    else

    console.log($scope.invited);

};

But this is not working, in the console the array is always empty.




Aucun commentaire:

Enregistrer un commentaire