【问题标题】:Angular - window.screen.height doesn't work on templateAngular - window.screen.height 不适用于模板
【发布时间】:2022-02-07 18:59:07
【问题描述】:

当我想在水平模式下针对手机优化部分模板时遇到问题。

TS:

window = window;

模板:

<div [ngStyle]="{'height': window.innerHeight < window.innerWidth ?
 window.screen.height : (widget == 'playlist' ? '334px' : '275px')}">
</div>

我没有从 window.screen.height 得到任何东西,但是当我记录它时,它返回了很好的值。我试图像值一样使用它,但结果是一样的。

【问题讨论】:

    标签: css angular typescript templates


    【解决方案1】:

    我认为你没有告诉你的风格height 它应该得到什么尺寸的单位。像素px,百分比%等。我添加了像素单位作为示例:

     <div [ngStyle]="{'height': window.innerHeight < window.innerWidth ?
        window.screen.height + 'px' : (widget == 'playlist' ? '334px' : '275px')}">
     </div>
    

    【讨论】:

    • 谢谢,我很怀念我忘记了设置的尺寸单位。
    猜你喜欢
    • 2017-02-26
    • 2021-12-06
    • 1970-01-01
    • 2016-05-17
    • 2017-04-10
    • 2018-06-18
    • 1970-01-01
    • 2018-01-13
    • 2015-07-23
    相关资源
    最近更新 更多