【问题标题】:NgStyle not being applied to htmlNgStyle 未应用于 html
【发布时间】:2021-01-23 21:24:02
【问题描述】:

我在下面有这个 ngStyle,就像这样工作

[ngStyle]="{'height': true ? '100vh' : null }"

但是当我使用这样的计算时不起作用(被应用)

[ngStyle]="{'height': true ? 'calc(100vh-100px)' : null }"

谁能告诉我为什么?

【问题讨论】:

    标签: html css angular calc ng-style


    【解决方案1】:

    - 前后都需要空格。像这样-

    [ngStyle]="{'height': true ? 'calc(100vh - 100px)' : null }"

    【讨论】:

    • 感谢您的帮助!有效。有没有更短的语法可以删除空值?显然用条件替换 true
    • 如果您想应用多个条件样式,那么您可以创建对象并传递它并在component.ts 中应用条件,例如。 - <some-element [ngStyle]="objExp">...</some-element> 或类似 <some-element [ngStyle]="getStyleObj()">...</some-element>
    猜你喜欢
    • 1970-01-01
    • 2019-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 2018-03-02
    • 2016-09-23
    • 2021-09-17
    相关资源
    最近更新 更多