Question

I'm working in a web application. I have a user list that i get from a database and use ng-repeat to list each entry by name like this:

JS:

   $http.get("cretecampaign.php?action=getExecutives").success(function(data) {
        $scope.executives = data;

PHP:

   <form name="myForm">
     <li ng-repeat="executive in executives" class="no-dots">
         <input type="checkbox" name="usertoadd" ng-model="executive.addto" >
         {{ executive.user }}
     </li>
   </form>

I need to pass the user id of the selected users on the list to myForm, but i can't figure out how to do this. I've pass the last few hours searching for an example code but can't find anything like this.

Was it helpful?

Solution

You can look at the $scope.executives array in your controller to find out which users are selected. If a user is selected, they will have a addto property.

So your code might look something like this:

$scope.submit = function(){
  var selected = [];
  angular.forEach($scope.executives, function(executive){
    if(executive.addto){
      selected.push(executive.user.id);
    }
  });
  //Do something with selected...
} 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top