2015-11-05 35 views
1

我想刪除單擊刪除按鈕時的條件列表項。現在只有過濾器正在刷新。表格沒有被刪除。建議通過這個。從div中刪除生成的元素angularjs

  • HTML

    <ul class="list-unstyled"> 
        <li style="display: inline-block" ng-repeat="crtia in newCriteria" > 
        <table> 
         <tr> 
    
         <td> 
          <select class="input-sm" ng-model="crtia.name" ng-options="searchopt for searchopt in searchcriteria " ng-click="searchy.check()"></select> 
         </td> 
         <td> 
          <input class="input-sm " ng-model="crtia.value" placeholder="{{crtia.name}}" ng-change="newList()" ng-click="searchy.check()" /> 
         </td> 
         <td> 
         <button type="button" class="btn btn-danger btn-xs" aria-label="Left Align" ng-click="removeCriteria($index)"> 
         <span class="glyphicon glyphicon-remove" aria-hidden="true" ></span> 
         </button> 
         </td> 
         </tr> 
    
        </table> 
        </li> 
    </ul> 
    
  • JS

     $scope.removeCriteria=function($index){ 
         $scope.searchy.check(); 
         alert($index); 
        $scope.newCriteria.splice($index,1); 
         $scope.newList();   //Refreshes the filter 
        } 
    
+0

plunkr:http://plnkr.co/edit/3yOmiIJ9Yu9RfAgmuVA7 –

+0

我正在修理你的問題等待 – Shohel

回答

1

試試這個

HTML

<button type="button" class="btn btn-danger btn-xs" aria-label="Left Align" data-ng-click="removeCriteria(crtia)"> 
    <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> 
</button> 

JS:

$scope.removeCriteria = function (sourceToRemove) { 
    $scope.searchy.check(); 

    var index = $scope.newCriteria.indexOf(sourceToRemove); 
    $scope.newCriteria.splice(index, 1); 
    $scope.newList();   //Refreshes the filter 
} 

更新Plunker

+0

燁工程....爲什麼通過$ index發送索引在這種情況下不起作用。 –

+1

對象索引和ng重複索引都是不同的 – Shohel