所以我有一个角度应用程序,如下所示:
'use strict';
//lib dependencies listed out
var $ = require('jquery');
var jQuery = $;
var bootstrap = require('bootstrap');
//controllers
var rootCtrl = require('./controllers/rootCtrl');
var reportCtrl = require('./controllers/reportCtrl');
var myReportsCtrl = require('./controllers/myReportsCtrl');
var userCtrl = require('./controllers/userCtrl');
var modalCtrl = require('./controllers/modalCtrl');
//factories
var userFactory = require('./factories/userFactory');
var authTokenFactory = require('./factories/authTokenFactory');
var authInterceptor = require('./factories/authInterceptor');
//directives
var exertion = require('./directives/exertion');
//filters
var reportType = require('./filters/reportType');
var ui_router = require('angular-ui-router');
var ui_router_extras = require('ui-router-extras');
var ui_bootstrap = require('ui-bootstrap');
var routes = require('./routes');
var namespace = 'main';
var angular = require('angular');
var run = require('./run');
var app = angular.module(namespace, [
// inject:modules start
'ui.router',
'ct.ui.router.extras',
'ui.bootstrap'
// inject:modules end
], function config($httpProvider){
$httpProvider.interceptors.push('AuthInterceptor');
})
.constant('API_URL', 'http://localhost:5000')
.controller('rootCtrl', ['$scope', '$state', '$modal', 'UserFactory', rootCtrl])
.controller('modalCtrl', ['$scope', '$modalInstance', modalCtrl])
.controller('reportCtrl', ['$scope', '$state', reportCtrl])
.controller('myReportsCtrl', ['$scope', '$state', myReportsCtrl])
.controller('userCtrl', ['$scope', '$state', userCtrl])
.factory('UserFactory', ['$http', 'API_URL', 'AuthTokenFactory', '$q', userFactory])
.factory('AuthTokenFactory', ['$window', authTokenFactory])
.factory('AuthInterceptor', ['AuthTokenFactory', authInterceptor])
.directive('etExertion', [exertion])
.filter('reportType', reportType)
.config(routes)
.run(['$rootScope', '$state', 'UserFactory', run]);
module.exports = app;
这样过滤器:
'use strict';
module.exports = function() { return function(input, report_type) {
input = input || [];
var out = [];
angular.forEach(input, function(item){
if(item.name == 'Other' || item.report_type == report_type)
{
out.push(item);
}
});
return out;
}; }
每当我尝试像这样包含过滤器时:
.filter('reportType', function(){ return function(input, report_type) {
input = input || [];
var out = [];
angular.forEach(input, function(item){
if(item.name == 'Other' || item.report_type == report_type)
{
out.push(item);
}
});
return out;
}; })
一切正常但是如果我这样做了之前我无法让控制台记录并且角度没有正确执行过滤。我在这做错了什么?如果我将reportType变量记录到主应用程序中的控制台,我会得到与我的过滤器文件中的内容相同的内容。