app.component.ts@Input() xAxis: Array = ['1月', '2月', '3月', '4月', '5月']实践2根据不同值设定不同样式
当前位置:   article > 正文

【angular-基础教程】属性指令NgStyle

ngstyle

作用

NgClass —— 添加和删除一组 CSS 类。
NgStyle —— 添加和删除一组 HTML 样式。
NgStyle—adds and removes a set of HTML styles.
NgModel —— 将数据双向绑定添加到 HTML 表单元素。

实践1

app.component.html

<img [ngStyle]="{width: '30px', height: '40px'}">
  • 1

带三元运算符

[ngStyle]="{'padding-top': crumbData.length == 0 ? '0' : '24px'}"
  • 1

实践2

根据不同值设定不同样式

<button nz-button 
    nzType="primary" 
    [ngStyle]="{'backgroundColor': getColor(num)}">{{num}}
</button>
  • 1
  • 2
  • 3
  • 4
  getColor(num: any) {
    if (num == 1){
      return "red"
    }
    if(num == 2){
      return "green"
    }
    return "orange"
  }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/436133
推荐阅读
相关标签