Interpolation of more than one expression inside an ng-repeat element causes one expression to not render
Here's an example:
<li id="{{friend.name}}" data-id="{{friend.name}}" ng-repeat="friend in friends">
This will be rendered as:
<li id="{{friend.name}}" data-id="John" ng-repeat="friend in friends" class="ng-scope ng-binding">
Notice that the id attribute isn't interpolated. It works fine if you just have one template expression in the element like so:
<li id="{{friend.name}}" ng-repeat="friend in friends">
You can see this in action here: http://jsfiddle.net/rmanalan/WCmtF/
I am wondering if it is because the affected attributes are the same but for the data- prefix. If you try changing the data-id to data-x, it seems to work okay. See amended fiddle: http://jsfiddle.net/WCmtF/1/
I am guessing this might be to do with how Angular is able to read its directives in various forms (ng-repeat, data-ng-repeat, x-ng-repeat, see Invoking Directives from HTML, here: http://docs.angularjs.org/guide/directive) and it might be getting confused between id and data-id.
It looks like the interpolation doesn't work for just the id attribute. As @symblify said, it's probably a conflict between id and data-id.
What is the use case for needing to interpolate those ids?
I was converting a backbone app that used both id and data-id and discovered the problem. I've worked around it but thought that it was a valid bug.
On Aug 24, 2012, at 7:05 AM, Brian Ford [email protected] wrote:
It looks like the interpolation doesn't work for just the id attribute. As @symblify said, it's probably a conflict between id and data-id.
What is the use case for needing to interpolate those ids?
— Reply to this email directly or view it on GitHub.
Just speculating, but did the backbone app use the ids as hooks to do DOM manipulation? If so, even having interpolation for ids wouldn't help you to implement your application with AngularJS idioms. I suspect that for this reason, interpolation of ids is purposefully omitted in favor of the data- prefixed one to discourage building apps like that. Still, if you need to change the id of some element, you could write that logic in a directive.
I couldn't possibly predict the needs of every application though, so if there is some good use case for having id interpolation, I will gladly re-open this issue. Otherwise I'm closing it for now. @IgorMinar, @vojtajina, @mhevery, can you weigh in on this when you get a chance?
Still, thanks for filing the bug! It's always good to review these design decisions and re-evaluate them.
Thanks. I'm still working on grokking angularjs. Rewriting one of my backbone apps is helping me to get there. I'm still trying to figure out the best approach for how to structure stuff. If you're interested, the code I'm rewriting is this:
https://github.com/rmanalan/rest-api-browser/blob/master/index.html https://github.com/rmanalan/rest-api-browser/blob/master/js/rab.js
No problem. That's a nifty looking project! You should post that to the mailing list if you haven't already. I'm sure there are some others who would be interested in it, and might be able to give you help and guidance if you need it. :)