我希望有一个占位符,例如,当过滤器结果返回空时,<No result>
。有人能帮帮忙吗?我都不知道从何说起。
HTML :
<div ng-controller="Ctrl">
<h1>My Foo</h1>
<ul>
<li ng-repeat="foo in foos">
<a href="#" ng-click="setBarFilter(foo.name)">{{foo.name}}</a>
</li>
</ul>
<br />
<h1>My Bar</h1>
<ul>
<li ng-repeat="bar in bars | filter:barFilter">{{bar.name}}</li>
</ul>
</div>
JS :
function Ctrl($scope) {
$scope.foos = [{
name: 'Foo 1'
},{
name: 'Foo 2'
},{
name: 'Foo 3'
}];
$scope.bars = [{
name: 'Bar 1',
foo: 'Foo 1'
},{
name: 'Bar 2',
foo: 'Foo 2'
}];
$scope.setBarFilter = function(foo_name) {
$scope.barFilter = {};
$scope.barFilter.foo = foo_name;
}
}
JsFiddle : < a href = “ http://jsFiddle.net/adrn/PEumV/1/”> http://jsFiddle.net/adrn/peumv/1/
谢谢!