How to obtain previous item in ng-repeat?

后端 未结 4 908
陌清茗
陌清茗 2020-12-03 00:51

I have a template in which I want to generate some HTML only if the current item has some different fields from the previous item. How can I access the previous item in an

4条回答
  •  悲&欢浪女
    2020-12-03 01:27

    One way is to use the $index for targeting previous item:

    HTML:

    {{$index}}:

    JS:

    app.controller('AppController',
        [
          '$scope',
          function($scope) {
            $scope.items = [
              {name: 'Misko'},
              {name: 'Igor'},
              {name: 'Vojta'}
            ];
    
          }
        ]
      );
    

    Plunker

提交回复
热议问题