Using comma as list separator with AngularJS
You could do it this way: <b ng-repeat=”email in friend.email”>{{email}}{{$last ? ” : ‘, ‘}}</b> ..But I like Philipp’s answer 🙂
You could do it this way: <b ng-repeat=”email in friend.email”>{{email}}{{$last ? ” : ‘, ‘}}</b> ..But I like Philipp’s answer 🙂
Based on @pilau s answer – but with an improvement that even the accepted answer does not have. <div class=”angular-with-newlines” ng-repeat=”item in items”> {{item.description}} </div> /* in the css file or in a style block */ .angular-with-newlines { white-space: pre-line; } This will use newlines and whitespace as given, but also break content at the … Read more
Indeed, you should use directives, and there is no event tied to the end of a ng-Repeat loop (as each element is constructed individually, and has it’s own event). But a) using directives might be all you need and b) there are a few ng-Repeat specific properties you can use to make your “on ngRepeat … Read more
My example code was correct and the issue was something else in my actual code. Still, I know it was difficult to find examples of this so I’m answering it in case someone else is looking. <div ng-repeat=”f in foos”> <div> <div ng-repeat=”b in foos.bars”> <a ng-click=”addSomething($parent.$index)”>Add Something</a> </div> </div> </div>
I would suggest using a custom filter such as this: app.filter(‘reverse’, function() { return function(items) { return items.slice().reverse(); }; }); Which can then be used like: <div ng-repeat=”friend in friends | reverse”>{{friend.name}}</div> See it working here: Plunker Demonstration This filter can be customized to fit your needs as seen fit. I have provided other examples … Read more
I tweaked this answer a bit and came up with this fiddle. Filter defined as: var myApp = angular.module(‘myApp’, []); myApp.filter(‘range’, function() { return function(input, total) { total = parseInt(total); for (var i=0; i<total; i++) { input.push(i); } return input; }; }); With the repeat used like this: <div ng-repeat=”n in [] | range:100″> do … Read more
You can use <li ng-repeat=”(name, age) in items”>{{name}}: {{age}}</li> See ngRepeat documentation. Example: http://jsfiddle.net/WRtqV/1/
Each ng-repeat creates a child scope with the passed data, and also adds an additional $index variable in that scope. So what you need to do is reach up to the parent scope, and use that $index. See http://plnkr.co/edit/FvVhirpoOF8TYnIVygE6?p=preview <li class=”tutorial_title {{tutorial.active}}” ng-click=”loadFromMenu($parent.$index)” ng-repeat=”tutorial in section.tutorials”> {{tutorial.name}} </li>
You can use ngShow. <li ng-show=”!events.length”>No events</li> See example. Or you can use ngHide <li ng-hide=”events.length”>No events</li> See example. For object you can test Object.keys.
Please see this: http://jsfiddle.net/JSWorld/Hp4W7/32/ <div ng-repeat=”division in divisions | orderBy:[‘group’,’sub’]”>{{division.group}}-{{division.sub}}</div>