我想为分页创建一个自定义指令,它显示基于文本搜索的过滤记录总数 请检查下面的代码:
<script>
var app = angular.module("myApp", []);
app.directive("testDir",function(){
return {
transclude: 'true',
link:function(scope, element, attr){
element.append(" Total filtered records: - <u> "+attr.filtered+"</u> of total records in object: <u>"+attr.unfiltered+"</u>")
},
template:"<br/><span ng-transclude> </span> "
};
});
app.controller("test",['$scope',function($scope){
$scope.details = [{value:"record1", other: "record1-value"},
{value:"record2", other: "record2-value"},
{value:"record3", other: "record3-value"}];
}]);
</script>
<div ng-controller="test">
Please enter text to filter table -
<input ng-model= "name">
<br/>
<table>
<tr ng-repeat = "detail in detailFilter=(details | filter:name)">
<td>{{detail.value}}</td>
</tr>
</table>
<hr>
Total filtered Records : {{detailFilter.length}}
<test-dir filtered="{{detailFilter.length}}" unfiltered="{{details.length}}">Displaying - </test-dir>
<hr>
detailFilter.length显示正确的长度,但是当我将其传递给指令时,它不会传递任何对象,即,即使长度为0也不会显示已过滤的记录。我想将两个对象的长度 detailFilter 和 details 传递给指令。
我之前没有使用指令,需要帮助。