我试图弄清楚为什么我的日期范围过滤器不起作用并且我得到了错误 - [$injector:unpr] Unknown provider: dateRangeProvider <- dateRange <- dashboardController. 我尝试将“dateRange”放在我的依赖项和 $filter 中,不确定我所做的是否正确。绝对感谢任何帮助!谢谢!
我试图在两个日期之间过滤以获取产品 ID 的 HTML
<input style="width:200px; padding:10px; border-radius:4px;"type="text" placeholder="search name" ng-model='productFilter'>
<input type="date" ng-model="to_date">
<input type="date" ng-model="from_date">
<div ng-repeat="product in products | dateRange : from_date : to_date | filter: productFilter track by $index">
<p>Total Inputs: {{product.createdAt}}{{product._id}}</p>
</div>
这是我的仪表板控制器
app.controller('dashboardController', ['$scope', '$filter', 'OpFactory', function($scope, $filter, OpFactory){
function getProducts(){
OpFactory.getProducts(function(data){
$scope.products = data;
console.log("data from getProducts function in dashboardcontroller", data);
})
}
getProducts();
$filter('dateRange', function() {
return function( product, fromDate, toDate ) {
var filtered = [];
console.log(fromDate, toDate);
var from_date = Date.parse(fromDate);
var to_date = Date.parse(toDate);
angular.forEach(product, function(item) {
if(item.completed_date > from_date && product.completed_date < to_date) {
filtered.push(item);
}
});
return filtered;
};
});
}]);