我試圖在AngularJS上根據數據從數據庫中獲取數據來顯示帶有動態過濾器(位置 - 值,如US,IN,CA等)的員工詳細信息。我嘗試過多種方式,但都沒有成功。請幫助完成Checkboxlist中的動態過濾器。複選框列表ng-repeat過濾器動態angularjs
我的代碼示例如下:
<html>
<body ng-app="myapp" ng-controller="myController">
<div >Location</div>
<table>
<tbody>
<tr ng-repeat="empL in EmpResult | unique : 'Location'">
<td>
<span>
<input type="checkbox" ng-model="loc" value={{empL.Location}} />
{{empL.Location}}
</span>
</td>
</tr>
</tbody>
</table>
<table align="left" style="width: 100%" class="table">
<thead>
<tr>
<th align="left" style="width: 30%">Employee</th>
<th align="left" style="width: 20%">Address</th>
<th align="left" style="width: 15%">Location</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="empN in EmpResult | filter : loc">
<td align="left" style="width: 30%">{{empN.EmpName}}</td>
<td align="left" style="width: 10%">{{empN.Address}}</td>
<td align="left" style="width: 15%">{{empN.Location}}</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
var myapp = angular.module('myapp', ['ui.unique'])
.controller("myController", function ($scope, $http) {
$http({
method: 'Get',
params: { strName: $scope.strName },
url: 'Emp.asmx/GetEmpbyName'
}).then(function (response) {
$scope.EmpResult = response.data;
})
});
</script>
</body>
</html>
據我所知,過濾器不工作方式。你必須定義一個實際的過濾方法(不是像你所做的那樣只使用一個範圍變量)。檢查文檔。在這裏你有一個很好的描述和非常簡單的例子,可以滿足你的需求:https://docs.angularjs.org/api/ng/filter/filter – FDavidov
@FDavidov這是真的,但@Ravi使用的過濾器來自依賴'ui.unique'他已經注入到他的模塊中,所以不需要定義。然而,這種依賴性是貶值的,所以我的問題是爲什麼要使用折舊的依賴關係? –