Monday, December 16, 2013

Drop rows out of a HTML table in AngularJS with an update to a scope variable!

I'm making things too hard here. If you are using AngularJS, you may just drop a row in a table by dropping a record from the array that feeds the table if that array is in a $scope variable! Angular is taking some getting used to. :P

$scope.removeAsset = function(asset) {
   var counter = 0;
   angular.forEach($scope.assets, function(scopeasset) {
      if (scopeasset.pKey == asset.pKey) {
         $scope.assets.splice(counter, 1);
      }
      counter++;
   });
}

 
 

The rows must repeat in the table based upon a binding to the $scope variable like so:

<tr ng-repeat="asset in assets">

No comments:

Post a Comment