javascript - angularjs ng-repeat 循環(huán)不同的樣式
問(wèn)題描述
我想實(shí)現(xiàn) 跳轉(zhuǎn)按鈕是紅色,刪除按鈕是藍(lán)色,添加是白色,但是目前這樣循環(huán)的話,全是“btn-warning”這個(gè)樣式,也就是紅色!
angular.module(’demoAPP’).controller(’demoCtrl’, function($scope) { var demoData = [ { 'Name' : '操作', 'action' : '跳轉(zhuǎn)' }, { 'Name' : '操作', 'action' : '刪除' } { 'Name' : '操作', 'action' : '添加' } ] $scope.demo = demoData; });
<table> <tr ng-repeat='item in demo'> <td>{{item.Name}}</td> <td><button type='button' class='btn btn-warning'>{{item.action}}</button></td> </tr> </table>
問(wèn)題解答
回答1:ng-class應(yīng)該可以搞定。
回答2:ng-class='{’樣式’:item.action==’跳轉(zhuǎn)’}'ng-class='{’樣式’:item.action==’添加’}'ng-class='{’樣式’:item.action==’修改’}'ng-class為true時(shí)執(zhí)行樣式
回答3:ng–class中多個(gè)樣式用逗號(hào)隔開(kāi),在重復(fù)里面把三個(gè)判斷都寫(xiě)上。
相關(guān)文章:
1. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問(wèn)題2. PHP求助,求幫忙謝謝各位3. extra沒(méi)有加載出來(lái)4. mysql - php 如何網(wǎng)址中出現(xiàn)該頁(yè)標(biāo)題?5. javascript - 天貓首頁(yè)首屏數(shù)據(jù)來(lái)源6. javascript - 釘釘?shù)膃xcel, word文件預(yù)覽是直接用的微軟的office web app,不犯法嗎?7. 關(guān)于Mysql數(shù)據(jù)表行轉(zhuǎn)列8. django進(jìn)行數(shù)據(jù)庫(kù)的查詢9. 求救一下,用新版的phpstudy,數(shù)據(jù)庫(kù)過(guò)段時(shí)間會(huì)消失是什么情況?10. mysql - 為什么where條件中or加索引不起作用?
