Search code examples
htmlangularjssearchangularjs-scope

Angular search in a table


I want to make a search on the column SN in a table.

there many information in my table, I want to be able to search based on SN but when I add the filter it does not even load my table

This is what I did: in My controler my List is filled :

 $scope.List = {};


 MyServices.getList()
.success(function (data) {
    angular.forEach(data, function (value, index) {
            $scope.List[value.SN] = {
                Description: value.Description,
                SN: value.SN
            }
    });
})
.error(function (error) {
    $scope.status = 'Unable to load customer data: ' + error.message;
});

and this is my HTML:

<label>Search: <input ng-model="search.SN"></label>
<tr ng-repeat="V in List| filter:search">
    <td>{{V.SN}}</td>
    <td>{{V.Description}}</td>
</tr>

Solution

  • You must write as follow:

       <label>Search: <input ng-model="search.SN"></label>
        <tr ng-repeat="V in List| filter: {SN: search.SN}">
        <td>{{V.SN}}</td>
        <td>{{V.Description}}</td>
        </tr>