http://plnkr.co/edit/nEfBE33AJen3mz9YvjeC?p=preview如何切換以ng重複多份初始項目
我有一些數據,填充一個列表,我想第3項在該列表中,以獲得selected
類。
我能夠給第一個項目,或任何單一的項目,類與下面的代碼,但我的問題是你將如何切換第一次加載多個項目?
.controller('PageCtrl',
['$scope',
function($scope) {
var vs = $scope;
vs.message = "1st, 2nd and 3rd item should be selected by default:";
vs.toggleTags = { item: 0 }; // This gives the first item the selected class
vs.myModel = [
{name: 'aaa'},
{name: 'bbb'},
{name: 'ccc'},
{name: 'ddd'},
{name: 'eee'},
{name: 'fff'},
{name: 'ggg'}
];
}]);
HTML:
<ul>
<li ng-repeat="m in myModel" data-ng-class="{'selected':toggleTags.item == $index}">
<div class="tag">{{m.name}}</div>
</li>
</ul>
不錯!乾淨的語法:)我看到這可以用來輕鬆加載自定義保存的選定設置。 –