L
L
lohmag2016-10-05 12:21:21
JavaScript
lohmag, 2016-10-05 12:21:21

How to remove elements in Angular?

I wrote the following code that creates DOM elements:

<tr ng-repeat="allowedMac in allowedMacs">
        <td class="td-username">{{allowedMac.name}}</td>
        <td class="td-ipaddress">{{allowedMac.ip}}</td>
        <td class="td-macaddress">{{allowedMac.mac}}</td>
        <td class="td-date">{{allowedMac.date}}
          <button class="delete-record" ng-click="">&#10060</button>
        </td>
      </tr>

How to hang on each created element ng-click, which will remove it? Removal, as I understand it, is to remove an entry from the allowedMacs array. How to take the contents of {{allowedMac.mac}} after ng-click is fired to send a POST request?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Osher, 2016-10-05
@lohmag

<button ng-click="removeAddr(allowedMac)">remove</button>

var allowedMacs = [];

function removeAddr(allowedMac) {
  $http.delete('/macs/' + allowedMac.mac).then(function (response) {
    if (response.success) {
      allowedMacs.splice(allowedMacs.indexOf(allowedMac), 1);
  });
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question