尝试遵循一些示例,但我得到应用程序未定义
app.js
(function () {
"use strict";
var app = angular.module("deviceManagement",['angularUtils.directives.dirPagination']);
}());
所以我希望能够使用或附加到“应用程序”
我有一个 Controller js文件
(function () {
"use strict";
angular
.module("deviceManagement")
.controller("DeviceListCtrl",
ProductListCtrl);
function ProductListCtrl($http, $scope) {
var vm = this;
vm.devices = [];
deviceList();
function deviceList() {
//..........
}
}
} ());
然后就在上面的代码下我这样做了
app.filter('deviceStatus', function () {
var deviceStatusLookup = {
1: "New Device",
2: "Activated",
3: "Unactivated"
};
return function (statusId) {
var output = deviceStatusLookup[statusId];
return output;
}
});
页面控制台错误
deviceListCtrl.js:73 Uncaught ReferenceError: app is not defined
最佳答案
检查您是否已包含 app.js 文件。
另外,我会更改以下内容:
app.filter('deviceStatus', function () {
对此:
angular
.module("deviceManagement")
.filter('deviceStatus', function () {
最好不要使用 var app 并仅引用模块,例如 Angular 模块(“设备管理”)。看这个answer .
关于javascript - 在函数外部添加自定义过滤器时,Angular 应用程序未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39282324/