javascript - Angular app is not defined when adding a custom filter outside of function -


trying follow examples, app not defined

app.js

(function () {    "use strict";    var app = angular.module("devicemanagement",['angularutils.directives.dirpagination']); }()); 

so have hoping able use or attach "app"

i have controller js file

(function () {    "use strict"; angular     .module("devicemanagement")     .controller("devicelistctrl",     productlistctrl);  function productlistctrl($http, $scope) {     var vm = this;      vm.devices = [];      devicelist();       function devicelist() {        //..........     }    } } ()); 

then right under above code this

app.filter('devicestatus', function () {      var devicestatuslookup = {         1: "new device",         2: "activated",         3: "unactivated"     };      return function (statusid) {         var output = devicestatuslookup[statusid];         return output;     } }); 

error on page console

devicelistctrl.js:73 uncaught referenceerror: app not defined 

check have included app.js file.

also, change below:

app.filter('devicestatus', function () { 

to this:

angular     .module("devicemanagement")     .filter('devicestatus', function () { 

it idea not use var app , refer module, e.g. angular.module("devicemanagement"). see answer.


Comments