Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.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
Javascript ng如果在ng中重复angularjs_Javascript_Angularjs - Fatal编程技术网

Javascript ng如果在ng中重复angularjs

Javascript ng如果在ng中重复angularjs,javascript,angularjs,Javascript,Angularjs,我需要根据ng repeat中冠军的价值定义不同的风格,我尝试以下方法: <thead> <tr><th>#</th><th>Nom</th><th>Ville</th><th style="width: 50%;">Lignée</th></tr> </thead> <tbody> <tr ng-repeat="alt

我需要根据ng repeat中冠军的价值定义不同的风格,我尝试以下方法:

<thead>
    <tr><th>#</th><th>Nom</th><th>Ville</th><th style="width: 50%;">Lignée</th></tr>
</thead>
<tbody>
    <tr ng-repeat="alternate1 in alternateViewText1.features | orderBy:'fiche.id*1'">
        <td>{{alternate1.fiche.id}}</td>
        <td ng-if="alternate1.properties.statut_activite == 'yes'" style="color: green;">{{alternate1.properties.nom}}</td>
        <td ng-if="alternate1.properties.statut_activite == 'no'" style="color: red;">{{alternate1.properties.nom}}</td>
        <td>{{alternate1.properties.ville}}</td>
        <td>{{alternate1.properties.lignee}}</td>
    </tr>
</tbody>

#诺姆维列涅
{{alternate1.fiche.id}
{{alternate1.properties.nom}
{{alternate1.properties.nom}
{{alternate1.properties.ville}
{{alternate1.properties.lignee}
它不工作(没有显示)


如何自动定义具有特定值的样式?

您可以为特定样式创建一个类,并像这样使用
ng class

css:

html

<td data-ng-class="{'green' : alternate1.properties.statut_activite == 'actif', 'red': alternate1.properties.statut_activite == 'inactif'}">{{alternate1.properties.nom}}</td>
{{alternate1.properties.nom}

您在测试中使用了错误的值

yes
替换为
actif
并将
no
替换为
inactif

例如:

<td ng-if="alternate1.properties.statut_activite == 'actif'" style="color: green;">{{alternate1.properties.nom}}</td>
<td ng-if="alternate1.properties.statut_activite == 'inactif'" style="color: red;">{{alternate1.properties.nom}}</td>
{{alternate1.properties.nom}
{{alternate1.properties.nom}

PS:


ssilas777的答案是执行css类此切换的最佳方式

请提供fiddleWhy
data ng class
而不是
ng class
?这是可选的,两者都是相同的,为了使模板有效的HTML,我们可以使用data-*属性。为什么不合并成一个
td
?表达式可能类似于:
ng class=“{'green':alternate1.properties.statut\u activite=='yes','red':alternate1.properties.statut\u activite=='no'}”
。此解决方案将输出两次名称。只显示一次:
ng class={'green':…statute\u activite=='yes','red':…statute\u activite=='no'}
。啊,这就是rit!,我没有注意到这两个都是相同的值。很好,你发现应该使用“actif”和“inactif”,但我坚信ng类应该是更好的选择。是的,我知道,我在你的回复中这样说;)
<td ng-if="alternate1.properties.statut_activite == 'actif'" style="color: green;">{{alternate1.properties.nom}}</td>
<td ng-if="alternate1.properties.statut_activite == 'inactif'" style="color: red;">{{alternate1.properties.nom}}</td>