【发布时间】:2014-09-29 14:21:24
【问题描述】:
我对 AngularJS 还是很陌生。我正在尝试更改表格元素的颜色,以便在用户对此选项进行投票时将其变为黄色。
<div ng-show="poll.userVoted">
<table class="result-table">
<tr ng-repeat="choice in poll.choices">
<td>{{choice.text}}</td>
<td>
<table ng-if="choice.text == poll.userChoice.text" style="background-color: yellow; width: {{choice.votes.length/poll.totalVotes*100}}%; text-align: right">
<tr>
<td>{{choice.votes.length}}</td>
</tr>
</table>
<table ng-if="choice.text != poll.userChoice.text" style="background-color: lightblue; width: {{choice.votes.length/poll.totalVotes*100}}%; text-align: right">
<tr>
<td>{{choice.votes.length}}</td>
</tr>
</table>
</td>
</tr>
</table>
【问题讨论】:
-
如果我正确理解您的问题标题,您可以尝试这样的事情 - plnkr.co/edit/jeszGorMQmLiqhtWDt94?p=preview
-
谢谢我会做这样的事情。我只是想我可以在标签中以某种方式做到这一点,而无需为其创建函数。
标签: css angularjs conditional