2013-04-08 28 views
2

我正在使用AngularJS與twitter bootstrap。我的問題的小提琴可以找到hereAngularJS-ng-switch不按預期方式工作

在這裏討論的HTML代碼是:

<button type="button" class="btn" ng-repeat="tool in toolBar"> 
    <div ng-switch on="tool.action"> 
     <i class="icon-plus-sign" ng-switch="insert"></i> 
     <i class="icon-edit" ng-switch-when="edit"></i> 
     <i class="icon-trash" ng-switch-when="delete"></i> 
    </div> 
</button> 

和範圍是:

$scope.toolBar = [ 
    { 
     "action": "insert" 
    }, 
    { 
     "action": "edit" 
    }, 
    { 
     "action": "delete" 
    }   
]; 

問題是,我要顯示每個按鈕只有一個,但不知何故不是更圖標顯示兩個圖標。

我在做什麼錯?

+2

您在第一個圖標上缺少「何時」。如果你修復它會起作用。 – ganaraj 2013-04-08 21:02:13

+0

謝謝!你能否提出這個答案,以便我可以解決這個問題 – callmekatootie 2013-04-08 21:15:26

回答

4

您錯過了when

<button type="button" class="btn" ng-repeat="tool in toolBar"> 
    <div ng-switch on="tool.action"> 
     <i class="icon-plus-sign" ng-switch-when="insert"></i> 
     <i class="icon-edit" ng-switch-when="edit"></i> 
     <i class="icon-trash" ng-switch-when="delete"></i> 
    </div> 
</button> 

更換你的HTML,它應該工作的罰款。