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.
Asked
Active
Viewed 740 times
0
-
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. May 26 '15 at 10:04
-
Hi. Did you find a better way to solve this issue thant defining a home made filter ? – sebastienbarbier Jun 09 '15 at 11:35
1 Answers
2
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

Community
- 1
- 1

sebastienbarbier
- 6,542
- 3
- 29
- 55