I think it would be easy to use $last
if you only want to add an ID to the last element.
app=angular.module('SampleApp',[]);
app.controller('SampleCtrl',[
'$scope',
function($scope){
return$scope.items=[
{
'name': 'Item1',
'price'—1200
},
{
'name': 'Item2',
'price'—1000
},
{
'name': 'Item 3',
'price'—1600
},
{
'name': 'Item 4',
'price'—2000
},
{
'name': 'Item 5',
'price'—1800
}
];
}
]);
ul{
list-style: none;
padding-left:0;
}
# last_element{
color:#ff0000;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<bodying-app='SampleApp'>
<div class='container'ng-controller='SampleCtrl'>
<h4>Change color by "#last_element"</h4>
<ul>
<ling-repeat='item in items'>
<div ng-attr-id="{{$last&'last_element'}}}">Name: {{item.name}},Price: {{item.price}}}</div>
</li>
</ul>
</div>
</body>
© 2024 OneMinuteCode. All rights reserved.