javascript - angular templating: ng-repeat comma-separated links -


i got disappointed angular... i'm trying quite simple presentation-layer stuff , can see no solution while browsing web (and stack overflow well).

the case is: i've got list of elements generate links to, of them comma-separated in html. let's it's:

var list = [{id: 1, name: "ab"},{id:2, name: "cd"}, ...]; 

my link should like:

<a href="#/somelink/{{ el.id }}">{{ el.name }}</a> 

easy, isn't it? so, basing on other questions, tried this:

<a ng-repeat="el in list" href="#/somelink/{{ el.id }}">{{ el.name }}</a>{{$last ? '' : ', '}} 

which doesn't work, because ng-repeat inside ng-repeat , $index, $last, $first caught outer ng-repeat values instead of inner one, want.

moreover, don't making html one-liner 5 things @ time, because [1] costs read , [2] it's easier mess something, while changing, because of complexity. prefer split more lines. but @ same time, don't want space before comma, i.e. el1 , el2. should el1, el2. , last thing - comma shall not in link, because element name should linked; comma justa separator, right?

it seems trivial case todo in js-templating engines (mustache, hbs, etc.), python, php, ruby, - , can't find clean solution in angular. not mention builtin ng-repeat doesn't support such fundamental feature.

can try code:

<span ng-repeat="el in list">     <a href="#/somelink/{{ el.id }}">{{ el.name }}</a>{{$last ? '' : ', '}} </span> 

it slight modification form code, added outer span repeat


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -