Angularjs - remove items selected according to checkbox

Asked

Viewed 445 times

1

How do I get the ids of the selected items from the checkbox(s) to send to the backend and later remove?

       <a href="">
            **O QUE PASSO POR PARAMETRO PARA A FUNÇÃO? **
            <i class="material-icons" title="Remover" ng-
            click="removeEntry(allEntries)">delete</i>
        </a>


        <tr ng-repeat="entry in allEntries | filter: search as results">


            <td>
                ** OQUE EU PASSO NO MODEL DO CHECKBOX ?**
                <input ng-model="???????" type="checkbox" 
                 id="item-"> 
            </td>
            <td style="max-width: 100px">{{entry.value}}</td>
            <td style="max-width: 100px">{{entry.type}}</td>
            <td style="max-width: 100px">{{entry.date}}</td>
            <td style="max-width: 100px">{{entry.category}}</td>
            <td style="max-width: 100px">{{entry.description}}</td>
        </tr>
  • what is the entry? has the example that can put ?

  • Opa Virgilio, entry is the object of all grid launches. Let’s assume I have two launches on the grid and want to delete them at once. I want the release ids to be sent to the removeEntry function, but I don’t know how to pass in html.

  • you want to delete and which of these items is the id, I even made an answer but, there is enough information missing! What is the element that identifies each entry? " for me to edit, "another point has to register this object by adding an extra item to set its true status to delete false to keep until that I’ve done it.

1 answer

0


angular.module("app", [])
  .controller("ctrl", ["$scope",
    function($scope) {
      $scope.allEntries = [{
        'value': 1,
        'type': 2,
        'date': '01/01/1999',
        'category': 3,
        'description': 'd1'
      }, {
        'value': 10,
        'type': 20,
        'date': '20/01/1999',
        'category': 30,
        'description': 'd20'
      }, {
        'value': 40,
        'type': 50,
        'date': '25/01/1999',
        'category': 60,
        'description': 'd60'
      }];
      $scope.removeEntry = function() {
        angular.forEach($scope.allEntries,
          function(a, b) {
            if (!(typeof a.status == "undefined") &&
              a.status) {
              console.log(a.status);
            }
          });
      };
      $scope.isHas = function() {
        for (let i = 0; i < $scope.allEntries.length; i++) {
          var a = $scope.allEntries[i];
          if (!(typeof a.status == "undefined")) {
            if (a.status) 
            {
              return true;
            }
          }
        }
        return false;
      };
    }
  ]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>


<div ng-app="app" ng-controller="ctrl">
  <div style="height:18px">
  <a href="" ng-click="removeEntry()" ng-show="isHas()">
    <i class="material-icons" title="Remover">delete</i>
  </a>
  </div>
  <table>
    <tr ng-repeat="entry in allEntries">
      <td>
        <input ng-model="entry.status" type="checkbox">
      </td>
      <td style="max-width: 100px">{{entry.value}}</td>
      <td style="max-width: 100px">{{entry.type}}</td>
      <td style="max-width: 100px">{{entry.date}}</td>
      <td style="max-width: 100px">{{entry.category}}</td>
      <td style="max-width: 100px">{{entry.description}}</td>
    </tr>
  </table>
  <div>

  • 1

    It worked, man, thank you very much! D

Browser other questions tagged

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