javascript - AngularJS: Prevent displaying the last separator when repeating multiple arrays -
question: elegant way ensure last separator on each line never shown?
11|18|3|8|12|1|22|31|61| 11:18:3:8:12:1:22:31: 11,18,3,8,12,61, 1 22 31
note data originates 3 different arrays, e.g., data line 1 defined as:
$scope.numbers = [11,18,3,8,12]; $scope.specialnumbers = [1,22,31]; $scope.additionalnumbers = [61];
i see more elegant/angular way, finding last <li>
, remove separator using $element.find
, or similar.
i created little jsfiddle example demonstrate problem.
thanks
here complete solution, using proposed $last
check (only once) in combination array.concat
, supported in angular expressions , supports bindings. however, correctly repeat literals, need track $index
.
"<li ng-repeat='num in numbers.concat(specialnumbers,additionalnumbers) " + "track $index'>" + "<span>{{ num }}</span><span ng-if='!$last'>{{ separator }}</span>" + "</li>"
Comments
Post a Comment