我有一个简单的过滤器,它根据SQL的输入是否为真来放置两个语句之一
app.filter('yesNo', function() {
return function(input) {
return (input == '1') ? 'Skal tjekkes!' : 'Alt OK';
}
});
然后应该根据它改变一个菜单项;
<li role="presentation"><a href="#" data-ng-click="statusFilter = 'Ny ordre'">New Orders
<div ng-if="input == '1' | outdated">
<p>Needs to be checked: {{(orders | filter:{status:'ny ordre', outdated: '1'}).length}}</p>
</div>
<div ng-if="!input == '1' | outdated">Shows regardless</div>
</a></li>
我错过了什么,不知道是什么。 :(
答案 0 :(得分:1)
这里有一个示例,说明如何使用自定义过滤器功能:http://jsfiddle.net/alexdumitrescu/zv6cf7nq/
var myApp = angular.module('myApp', [])
.filter('myfilter', function() {
return function(orders) {
return orders.filter(function(order) {
return order.outdated == '1';
})
}
});
function MyCtrl($scope) {
$scope.orders = [{
status: 'my order1',
outdated: '1'
}, {
status: 'my order2',
outdated: '0'
}];
}
&#13;
<div ng-controller="MyCtrl">
{{orders | myfilter}}
</div>
&#13;