0

I am trying to add a filter to replace the "true, false" return values with a "Yes or No".

In my filters.js file I have a dotNetDate filter that formats the date, I believe I am supposed to put my second filter in here but then my first one breaks and and views that used it are now non-viewable. If I comment out what I put in its viewable again, any help on how to add second filter without other one breaking?

angular.module('PCAFilters', []).filter('dotNetDate', function () {
return function (input) {
     return moment(input).format("M/D/YYYY");
  };
});

//angular.module('PCAFilters', []).filter('yesNo', function () {
//    return function (input) {
//        return input ? 'Yes' : 'No';
//    };
//});
1
  • can you post your HTML code? Commented Nov 30, 2015 at 17:17

1 Answer 1

2

Try this:

angular.module('PCAFilters', []).filter('dotNetDate', function () {
    return function (input) {
       return moment(input).format("M/D/YYYY");
    };
}).filter('yesNo', function () {
    return function (input) {
        return input ? 'Yes' : 'No';
    };
});

You were defining the module PCAFilters twice. If you want to get a module, leave off the [], like this:

angular.module('PCAFilters').filter(...);

If you don't want to chain them together like I suggested, I would store the module in a local variable, instead of using angular.module for each filter definition. See below:

var filtersModule = angular.module('PCAFilters', []);

filtersModule.filter('dotNetDate', function () {
    return function (input) {
       return moment(input).format("M/D/YYYY");
    };
});

filtersModule.filter('yesNo', function () {
    return function (input) {
        return input ? 'Yes' : 'No';
    };
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.