AngularJSコントローラの結果をHTMLテーブルに条件付きでフォーマットする方法を考えています。これは、配列内の要素を操作するng-repeatの繰り返しの間にうまくいきます。ng-repeatの中で条件付き書式/スタイルを指定する
私が達成したいのは、コントローラ内の関数がtrueを返すときはいつでも、背景またはスタイルは緑色で、そうでないときは赤色になります。
挿入ポイントのコメントに「BEGIN QUESTION」と表示されます。
<!-- PLAYER STATS TABLE -->
<div id = "StatsListTable">
<table border="1" style="width:80%">
<tr> <!-- TODO: class="tr.pstats" -->
<th>Character Name</th>
<th>
<div ng-app="KIdash" ng-controller="controller">
Total Matches: {{TotalMatchesFunc()}} :: {{GreaterWins()}}
</div>
</th>
<th class="green">Wins</th>
<th class="red">Losses</th>
</tr>
<tr ng-repeat="ps in PlayerStats" class = "playerStatTable">
<td>{{ps.name}}</td>
<td>{{ps.matches}}</td>
<!-- BEGIN QUESTION -->
<!-- IF {{GreaterWins()}} make it green -->
<!-- ELSE make it red -->
<script type="text/javascript">
function() {
if(controller.GreaterWins())
{
<th class="green">{{ps.wins}}</th>
} else {
<th class="red">{{ps.wins}}</th>
}
}
</script>
<!-- END IF -->
<td>{{ps.losses}}</td>
</tr>
<table>
</div>
<!-- END PLAYER STATS TABLE -->
元の質問を更新したのはなぜですか?私はあなたがしたい場合は元の質問をそのまま残して、ソリューションで編集を追加すると言うだろう。 –