JFOX
JFOX

Reputation: 245

AngularJS Filter throwing "Object Uncaught" error when injected

When trying to add a set of filters to my Serenity app (https://github.com/jfox015/Serenity), I get an "Uncaught Object" error when trying to inject a filter into my app. When I remove the filters code from the app, it works fine. Can't figure out what's wrong with the filters so that they're not be recognized as valid resources. I had them as part of the global module and then a separate module and it still fails.

Here's the relevant code:

Filter code stored in app/src/admin/AdminFilters.js:

'use strict';

angular.module('AdminFilters', ['USER_ROLES'])
.filter('userRoleFilter', ['USER_ROLES',
    function(USER_ROLES) {
        return function(input) {
            return USER_ROLES[input];
        };
    }
])
.filter('dateJoinedFilter', 
    function() {
        return function(input) {
            var date = new Date(input);
            return (date.getMonth() + 1) + "/" + date.getDate() + "/" + date.getFullYear();
        };
    }
)
;

Angular App Declaration in app/src/app.js:

var angApp = angular.module("serenityApp", ['ngRoute', 'ngResource', 'angular-md5', 'AdminFilters'])

Usage in my Admin code (Abridged) in app/src/admin/adminUsersList.html:

<tbody>
    <tr  data-ng-if="users" data-ng-repeat="user in users">
       <td>{{ user.name }}</td>
       <td>{{ user.role | userRoleFilter }}</td>
       <td>{{ user.dateJoined | dateJoinedFilter }}</td>
       <td>{{ user.group }}</td>
    </tr>
    <tr data-ng-if="!users">
        <td colspan="4">No users were found.</td>
    </tr>
</tbody>

The relevant JS files are all included in the index.html file as well:

<script src="app/src/admin/AdminFilters.js" type="text/javascript"></script>
<script src="app/src/admin/AdminServices.js" type="text/javascript"></script>
<script src="app/src/admin/AdminController.js" type="text/javascript"></script>

Upvotes: 0

Views: 214

Answers (1)

DineshKP
DineshKP

Reputation: 364

Is the USER_ROLES in the AdminFilters, a module or constant?

If it is a constant belonging to another module then I believe it cannot be injected in AdminFilters module.

Upvotes: 1

Related Questions