猜測更簡單,更直截了當:
var app = angular.module('app', []);
app.controller('DisplayController', function($scope) {
$scope.ShowRest = 0;
$scope.items = [{
title: 'myTitle1'
}, {
title: 'myTitle2'
}, {
title: 'myTitle3'
}, {
title: 'myTitle4'
}, {
title: 'myTitle5'
}];
});
app.$inject = ['$scope'];
Then:
<div data-ng-controller="DisplayController">
<div data-ng-repeat="item in items">
<div data-ng-class="{'no-display': !$first}">{{ item.title }}</div>
</div>
<div data-ng-repeat="item in items" data-ng-show="ShowRest">
<div data-ng-class="{'no-display': $first}">{{ item.title }}</div>
</div>
<button data- ng-click="ShowRest = !ShowRest">Show rest</button>
</div>
也許這不是最有效的方式,但它的工作原理! 小提琴:http://jsfiddle.net/cb6pggL8/1/
Tahnks,但沒有作品... – user11001
@ user11001,嘗試'$ first'代替'$指數== 1',因爲索引開始從'0' – Grundy
@Grundy是正確的,對不起。或'$ index == 0' – IsraGab