你好我期待提供一個日期選擇器(材料套件用戶界面),當我返回頁面上的快照圖像列表時,過濾返回的快照的日期。不過,我得到一個注射器錯誤: angular.js:13920錯誤:[$注射器:unpr]未知提供商:dayFilterFilterProvider < - dayFilterFilter http://errors.angularjs.org/1.5.8/ $噴油器/ unpr P0 = dayFilterFilterProvider%20%3C-NaNayFilterFilterAngularJS datepicker返回快照
這裏該指令:
(function() {
"use strict";
app.controller("MainController", [
"$rootScope",
"$scope",
function ($rootScope, $scope) {
$scope.dayFilter = null;
$scope.dayFilter = function(items, date) {
return function(items, date) {
$rootScope.dateFilter = date;
var filtered = [];
var begin, end
begin = date.setHours(0, 0, 0);
end = date.setHours(23, 59, 59);
angular.forEach(items, function(item) {
if (item > begin && item < end) {
filtered.push(item)
}
})
console.log("Filtered day", date)
return filtered
}
};
$scope.dayFilter(new Date(), 'date');
這裏是HTML:
<div class="dropdown">
<h3 class="dropdown-toggle" id="day-datetimepicker" role="button" data-toggle="dropdown" data-target="#"> {{ filtered.date ? filtered.date.label : 'Day' }} <span class="caret"></span></h3>
<ul class="dropdown-menu" role="menu" aria-labelledby="day-datetimepicker">
<datetimepicker data-ng-model="dateFilter" data-datetimepicker-config="{
dropdownSelector: '#day-datetimepicker',
minView: 'day',
startView: 'day'
}" data-on-set-time="dayFilter(newDate, 'day')"></datetimepicker>
</ul>
</div>
<a ng-repeat="s in chui.snapshot | dayFilter:'day' | orderBy:'-date'"
ng-click="select('snapshot', s);
modal('snapshot-keyholder', true);"
class="snapshot-thumbnail col-xs-6 col-sm-4 col-md-3 col-lg-2"
>
讓我知道,如果您有任何進一步的問題。許多在此先感謝
在響應於第一答案我創造了這個模塊:
app.filter("dayFilter",[
function() {
return function dayFilter(items,date) {
var d = new Date();
var filteredItems = [];
var begin, end
begin = d.setHours(0, 0, 0);
end = d.setHours(23, 59, 59);
angular.forEach(items, function(item) {
if (item > begin && item < end) {
filtered.push(item);
}
})
console.log("Filtered day", d);
return filteredItems
}
$filter("dayFilter");
// dayFilter(new Date(),'date');
}]);
I no longer get an error, but the snapshots do not appear in the output, even though I get the following in the console:
iltered day Thu Nov 10 2016 23:59:59 GMT-0500 (COT)
main.js?v=2016-11-08-3:89 Filtered day Thu Nov 10 2016 23:59:59 GMT-0500 (COT)
main.js?v=2016-11-08-3:89 Filtered day Thu Nov 10 2016 23:59:59 GMT-0500 (COT)
main.js?v=2016-11-08-3:89 Filtered day Thu Nov 10 2016 23:59:59 GMT-0500 (COT)
main.js?v=2016-11-08-3:89 Filtered day Thu Nov 10 2016 23:59:59 GMT-0500 (COT)
main.js?v=2016-11-08-3:89 Filtered day Thu Nov 10 2016 23:59:59 GMT-0500 (COT)
main.js?v=2016-11-08-3:89 Filtered day Thu Nov 10 2016 23:59:59 GMT-0500 (COT)
main.js?v=2016-11-08-3:89 Filtered day Thu Nov 10 2016 23:59:59 GMT-0500 (COT)
main.js?v=2016-11-08-3:89 Filtered day Thu Nov 10 2016 23:59:59 GMT-0500 (COT)
喔在帖子中,我意識到我沒有關閉jabascript中的大括號,也沒有關閉html中的第一個div,但是在腳本中他們被關閉了(當我複製它們時,還有其他指令和腳本的其他部分相應到這個部分,所以我關閉了他們之後的部分。 –
'$ scope'不能注入到過濾器函數中。 '$ scope'只能注入到由'ng-controller'指令或自定義指令實例化的控制器中。 – georgeawg
有幫助,我做了進一步的編輯......是否有可能從我提供的信息(請參閱問題末尾的編輯)看看爲什麼我沒有得到所需的輸出? –