0

以下是使用ng-repeat和指令的可重複使用的進度條示例。在指令中的ng-repeat中添加上一個項目

Plunker

,因爲我有類.progressBar__isActive敵我當前頁或索引值。我想將progressBar__isComplete類添加到所有以前的列表項。 在代碼中,我

data-my-progress-bar data-currentPage="0" data-currentPageStyle="progressBar__isActive 

這將增加類當前目錄的項目。但假設我有data-currentPage =「2」。我想將progressBar__isComplete類添加到最後兩個列表項。

回答

1

取代納克級的與內容:

ng-class="{ {{cssActivePage}}: $index == indexActivePage, progressBar__isComplete : $index < indexActivePage}" 

雖然有效,但您可能希望使其更類似於{{cssActivePage}}

+0

謝謝。 yup working http://plnkr.co/edit/koqwCZa3U0pFLKHXxD6z?p=preview – future 2014-11-21 14:53:55

0

試試這個。您需要使用<=而不是=

HTML

<div data-my-progress-bar data-currentPage="2" data-currentPageStyle="progressBar__isActive" data-pages="['Step 1','Step 2','Step 3','Step 4']"> 
    </div> 

HTML進度

<li ng-repeat="page in allPages" ng-class="{ 'progressBar__isActive': $index == indexActivePage,'progressBar__isComplete' : $index < indexActivePage}"> 
     {{page}} 
     </li> 

Updated Code

+0

我不想爲以前的列表項添加相同的類名稱。 – future 2014-11-21 14:43:41

+0

正如Walter所建議的那樣,您可以在ng-class中添加一些diff類,但是您需要用單引號或雙引號將其包裝,以使其工作。 – 2014-11-21 14:47:09

+0

@JayShukla我看到它也沒有引號。但嚴格來說,你可能是正確的 – 2014-11-21 14:51:49

相關問題