Angularjs - Filter ng-repeat checkbox

Asked

Viewed 86 times

0

Keeping in mind that I have an ng-repeat, how do I pick up only the items I marked in the checkbox?

  • 1

    Could you enter what you were trying to please? http://answall.com/help/mcve

1 answer

0


Following example, see if it meets you.

function MyCtrl($scope) {
    $scope.itens = [
      {id: 1,name: "nome 1"}, 
      {id: 2,name: "nome 2"}, 
      {id: 3,name: "nome 3"}
    ];
    $scope.marcados = function() {
      var checkedItems = [];
      angular.forEach($scope.itens, function(item, arrayIndex) {
        if (item.id === true) {
          checkedItems.push(item)
        }

      })
      return checkedItems
    }
  }
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</script>
<div ng-app="" ng-controller="MyCtrl">

  <ul>
    <li ng-repeat="item in itens">
      <input type="checkbox" ng-model="item.id">{{item.name}}
    </li>
  </ul>
  {{itens}}
  <br><br>
  marcados: {{marcados()}}
</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.