我有一个列表,其中有几个元素来自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