Answer the question
In order to leave comments, you need to log in
How to separate ng-repeat with commas?
I have a book object, this object has an array of genres.
var book = { name:'Game Of Thrones', price: 19.95, author:'George R. R. Martin', genres:['Fantasy', 'Political strategy', 'High fantasy']};
<p>Genres: <strong ng-repeat="genre in store.product.genres">{{genre}}</strong></p>
<p>Genres: <strong ng-repeat="genre in store.product.genres">{{genre ? '' : ', '}}</strong></p>
Answer the question
In order to leave comments, you need to log in
Yes, what kind of people then went ... If you can do something in the templates, then everyone is trying to do it there.
angular.module('app').filter('join', function () {
return function (arr, glue) {
if (!Array.isArray(arr)) {return arr;}
return arr.join(glue);
};
});
<strong>{{store.product.genres | join : ', '}}</strong>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question