Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I am trying to use an array.map function in my ng-click expression:

addTracksToPlaylist(album.tracks.items.map(function(o){return o.id}));

but I am getting a syntax error Token '{' is unexpected, expecting [)] at column 47 of the expression. I don't really know what to do about this, I'm trying not to put the function in the scope or outside of my markup.

share|improve this question
    
That is because whenever you use expressions in angular it expects an angular expression which is a subset of javascript. otherwise script injection would be too easy. You'll have to settle for a function in your controller that returns the filtered array. You can create a $filter and use it instead. – Muli Yulzary Aug 7 at 20:24
    
@MuliYulzary Can you provide an example on how to use it with $filter? – Blu Aug 7 at 20:46
1  
Here's a snippet I made: plnkr.co/edit/MpqbmOXYrmmoWIirvr7q?p=preview – Muli Yulzary Aug 7 at 21:14
    
Thankskssssss this is what I needed – Blu Aug 7 at 21:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.