1

I want to delete the criteria list item on clicking the delete button. Right now only the filter is getting refreshed. The tables are not being deleted. Suggestions to get through this.

  • 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
        }
    
2

1 Answer 1

1

Try this

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
}

Update Plunker

Sign up to request clarification or add additional context in comments.

1 Comment

Object index and ng repeat index both are different

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.