Base solution for your next web application
Open Closed

Add filters to Angular #1034


User avatar
0
jimchristian created

The standard Web project has a file /app/main/filters/moment_filter.js with the "momentFromNow" filter. How do I add another filter to format dates in another way? I tried this to add a second filter like this:

angular.module('app')
    .filter('momentFromNow', function () {
        return function (input) {
            return moment(input).fromNow();
        };
    })
    .filter('momentFromNow2', function () {
        return function (input) {
            return moment(input).fromNow();
        };
    });

The project builds but I get an error at runtime:

angular.js:13236Error: [$injector:unpr] http://errors.angularjs.org/1.5.0/$injector/unpr?p0=momentFromNow2FilterProvider%20%3C-%20momentFromNow2Filter

It looks like I need to register my new filter, but where? Or am I using the wrong syntax to create a filter?


2 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    You are creating it in the right way. Probably your browser cached it. Disable caching of your browser while developing your project. Also, this is Angular topic and you can find more info on filters on the web.

  • User Avatar
    0
    jimchristian created

    Thanks - you were right, clearing the browser cache fixed the problem. I should have thought of that.