【发布时间】:2018-04-30 10:15:06
【问题描述】:
像 angularjs 1.x 如何实现 ngstyle 超过 2 个条件?
Angularjs 1.x:
<div ng-controller="MyCtrl">
<p ng-style="cond1 ? { color:'green' } : cond2 ? {color: 'blue'} : cond3 ? {color: 'red'} : {color: ''}">Hello World!</p>
</div>
Angular-2/4/5: 在下面的代码中,黑色、金色和绿色是打字稿中声明的变量。
<button class="button" id="btn_status" [ngStyle]="darked? {backgroundColor:'darked'} : gold?{backgroundColor:'gold'} : green?{backgroundColor:'green'}">
这里出现错误,
【问题讨论】:
-
[ngStyle]="{'color':cond1?'green':cond2?'blue':cond3?'red':''}" (" 之间的所有引号都是单引号)
-
或 [style.color]="cond1?'green':cond2?'blue':cond3?'red':''" (只有第一个和最后一个是双引号)
标签: angular angular5 angular2-template