How to Add IDs to the Last List in ng-repeat

Asked 2 years ago, Updated 2 years ago, 109 views

I would like to do automatic scrolling at the end of the list. I think I can do it with ng-attr-id and $index, but I don't know exactly what code to write.Please give me some advice.

monaca angularjs

2022-09-30 19:26

1 Answers

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>


2022-09-30 19:26

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.