我有一個列表,其中有幾個元素來自JSON文件。 我希望列表中的每個元素都具有從函數getNumber()中獲得的背景顏色,該函數將生成一個隨機數,然後返回與該隨機數對應的顏色。 現在我想通過調用getNumber()函數來設置每個div的背景顏色。Angularjs根據JSON設置列表元素的背景顏色
HTML代碼 -
<html ng-app="ionicApp">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>Radio Buttons</title>
<link href="//code.ionicframework.com/1.0.0-beta.12/css/ionic.css" rel="stylesheet">
<script src="//code.ionicframework.com/nightly/js/ionic.bundle.min.js"></script>
</head>
<body ng-controller="MainCtrl">
<ion-header-bar class="bar-positive">
<h1 class="title">Divs inside Div</h1>
</ion-header-bar>
<ion-content scroll="false">
<ion-scroll class="list" direction="y" style="height:100%">
<li class="item" ng-repeat="item in agendaDetails">
<div class="row speakerListItems" ng-repeat="speakering in item.speakers track by $index">
<div class="col-50">
<p style="float:left">{{speakering.speaker}}</p>
</div>
<div class="col-50">
<p style="float:right">Hello</p>
</div>
</div>
</li>
</ion-scroll>
</ion-content>
</body>
</html>
在這裏,我想通過調用getNumber給背景色,以每個列表項(),並檢查與該值對應的動態色彩。 這裏是codepen鏈結CODEPEN DEMO
你有沒有嘗試'ng風格' – Kulbhushan
我想在不同的div中使用不同的顏色,在ng-style中我只能給出一種顏色......我試過ng-style ='background-color =「getNumber()」'但那不是woorking – RHUL
請參閱我的答案,你的語法是錯誤的。 – Kulbhushan