Angular - window.screen.height 不适用于模板

Angular - window.screen.height doesn't work on template

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

TS:

window = window;

模板:

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

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

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

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