Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular and builtin javascript map function

Pretty new to angular so maybe I'm missing something obvious. I have a model with collection of objects with own properties; and I'm trying to create a csv value out of Text property of that object. I've tried few things and got it to work with both ng-repeat and by calling a function. However what I thought was the most straight forward way of doing this is not quite working.

{{item.Keywords.map(function (kw) { return kw.Text; }).join(', ')}}

In this example join works just fine (i see object separated by commas), however when combined with map it's unable to interpret it and just prints out it as is. Is there a trick to using map that I'm missing?

like image 857
Konstantin Avatar asked Aug 13 '26 04:08

Konstantin


1 Answers

Angular expressions can't do everything you can do in javascript. Check out the angular docs for expressions for more detail on what they can and can't do. I don't think you can declare a function in an angular expression so that is probably why your particular example is not working.

In general you should try to keep the logic in a view to a minimum. You can always just move the logic from your expression into a function on the controller.

like image 54
rob Avatar answered Aug 14 '26 16:08

rob