I have an array that I am iterating through and displaying. Sometimes, however, the item it finds is an array. I'd like to do something different with this, using an ng-if. I am unsure how to do this easily. It seems like a common issue but there doesn't appear to be an easy solution.
-
Can you expand your question more? What would you like to do if the item is an array? Can you provide a demo code (plunker)?Razvan B.– Razvan B.2015-05-26 10:04:12 +00:00Commented May 26, 2015 at 10:04
-
Hi. Did you find a better way to solve this issue thant defining a home made filter ?sebastienbarbier– sebastienbarbier2015-06-09 11:35:05 +00:00Commented Jun 9, 2015 at 11:35
Add a comment
|
1 Answer
You can use Angular.isArray() (see doc) but it does not exist as a already defined filter so you might need to define your own.
Something like that :
angular.module('...', []).filter('isArray', function() {
return function (input) {
return angular.isArray(input);
};
});
And then in your template usimply use {{ myVar | isArray }}.
My only concerne is ... is it really clean to do so ? I don't know but this will solve your problem.
By the way, was already asked on StakcOverFlow : Angular expression to check if model is array or object