AngularJS ng-repeat, comma separated with ‘and’ before the last item

$last is the truthy value.. so it holds either true or false and it doesn’t hold the last element index.. I guess below expression should solve your problem <p><span ng-repeat=”user in Users”> {{user.Username}} {{$last ? ” : ($index==Users.length-2) ? ‘ and ‘ : ‘, ‘}} </span></p> Also make sure that you have the expression with …

Read more

How to obtain previous item in ng-repeat?

You can do something like <div ng-app=”test-app” ng-controller=”MyController”> <ul id=”contents”> <li ng-repeat=”content in contents”> <div class=”title”>{{$index}} – {{content.title}} – {{contents[$index – 1]}}</div> </li> </ul> </div> JS var app = angular.module(‘test-app’, []); app.controller(‘MyController’, function($scope){ $scope.contents=[{ title: ‘First’ }, { title: ‘Second’ }, { title: ‘Third’ }] }) Demo: Fiddle Be careful: $index is for the directive …

Read more

AngularJS – Model not updating on selection of radio button generated by ng-repeat

<div ng-controller=”DynamicCtrl”> <input type=”radio” ng-model=”$parent.lunch” ng-repeat=”m in meat” ng-value=”m” name=”lunch”> {{lunch}} </div> Should do the trick. As I understand it, ng-repeat creates its own $scope. so you need to refer to the $parent $scope; Yes, AngularJS is tricky. Also you need to change the value to ng-value too.