Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 尝试有条件地使用ng样式_Angularjs - Fatal编程技术网

Angularjs 尝试有条件地使用ng样式

Angularjs 尝试有条件地使用ng样式,angularjs,Angularjs,下面的代码不会更改表的任何颜色。行上看不到红色或绿色(正确渲染的不同标签除外) 有什么想法吗 <table class="table table-striped table-hover"> <thead> <tr> <th>Player</th> <th>Number</th> <th>Still stan

下面的代码不会更改表的任何颜色。行上看不到红色或绿色(正确渲染的不同标签除外)

有什么想法吗

<table class="table table-striped table-hover">
    <thead>
        <tr>
            <th>Player</th>
            <th>Number</th>
            <th>Still standing?</th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="player in players" ng-style="player.standing ? '{'color':'green'}' : {'color':'red'}">
            <td ng-cloak>
                <span ng-show="player.standing">
                    {{player.name}}
                </span>
                <span ng-show="!player.standing">
                    <strike>{{player.name}}</strike>
                </span>
            </td>
            <td ng-cloak>{{ player.associatedNumber }}</td>
            <td ng-cloak>
                <span 
                    ng-class="player.standing ? 'label label-success': 'label label-danger'"
                    ng-show="player.standing">
                    Yes
                </span>
                <span 
                    ng-class="player.standing ? 'label label-success': 'label label-danger'"
                    ng-show="!player.standing">
                    No
                </span>
            </td>
        </tr>
    </tbody>
</table>

您的表达式没有为
ng style
生成有效的结果。你想要

ng-style="{color: player.standing ? 'green' : 'red'}"
您还可以使用相应的标签,以便这些标签与其他代码中的
标签对齐

<tr ng-repeat="player in players" ng-class="{
    'text-success': player.standing,
    'text-danger': !player.standing}">
而不是具有冗余逻辑的两个跨度

<tr ng-repeat="player in players" ng-class="{
    'text-success': player.standing,
    'text-danger': !player.standing}">
<span class="label" ng-class="{
    'label-success': player.standing,
    'label-danger': !player.standing
}">{{player.standing ? 'Yes' : 'No'}}</span>