angularjs - How to separate groups in ng-repeat -
i have items want show, using ng-repeat. want show in order (easy), whenever ordered attribute changes, want html in-between.
example: (fiddle):
<div ng-app ng-controller="main"> <div ng-repeat="item in items | orderby:'role'"> {{item.role}} - {{item.name}} </div> </div> function main($scope){ $scope.items = [{name: 'first', role: 1}, {name: 'second', role:2}, {name: 'third', role: 1}, {name: 'fourth', role: 2}]; }
i want print:
1 - first
1 - third
(some separator kode)
2 - second
2 - fourth
you want create function in scope.
$scope.currentrole = 'something'; $scope.createheader = function(role) { showheader = (role!=$scope.currentrole); $scope.currentrole = role; return showheader; }
and in html:
<div ng-app ng-controller="main"> <div ng-repeat="item in items | orderby:'role'"> <div ng-show="createheader(item.role)"> here header </div> {{item.role}} - {{item.name}} </div> </div>
Comments
Post a Comment