我有当它从工厂的阵列上运行未返回任何东西的过滤器。 但是,当我复制阵列直接粘贴到过滤器,它工作正常。 必须有一个简单的解决方案,它让我发疯了。
这工作:
$filter('filter')([
{"name":"firstItem","code":"one"},
{"name":"secondItem","code":"two"},
{"name":"thirdItem","code":"three"}
],"two",true);
这不:
$filter('filter')($scope.items,"two",true);
角示例:
angular.module('App', ['ngResource'])
.controller('Ctrl', function($scope, $filter, Items) {
$scope.items = Items.query();
var codeToFilter = "two";
$scope.badFilter = $filter('filter')($scope.items,codeToFilter,true);
$scope.goodFilter = $filter('filter')([
{"name":"firstItem","code":"one"},
{"name":"secondItem","code":"two"},
{"name":"thirdItem","code":"three"}
],"two",true);
})
.factory("Items", function ($resource) {
return $resource("item-list.asp");
});
而从阵列项目-list.asp返回:
[{"name":"firstItem","code":"one"},{"name":"secondItem","code":"two"},{"name":"thirdItem","code":"three"}]
这是我在页面上看到:
Bad Filter: []
Good Filter: [{"name":"secondItem","code":"two"}]