Search code examples
angularjsmeanangular-filtersmeanjs

Add an angular filter from an external file to mean js stack


I'm new to the mean js stack and all of it's sub components.

I want to include a function that will changes the dates from, eg "12/12/14" to "8 weeks ago". I found it here https://gist.github.com/rodyhaddad/5896883/. I think it's a new angular filter.

But how do I include it in my mean js stack? Do I put the file somewhere?

And after that, can I use this "timeago" filter just like any other angular filter? Or is there something special I have to do?

Thanks, Bran


Solution

  • You have to use this code on your module.

    angular.module('yourName').filter( ....
    

    You can place it in any file or in any existing file. If you place it in new file, make sure you include it with <script src="...">.

    After that you can use it

    {{variable | timeago}}
    <span ng-bind="variable | timeago : null: true"></span>