[英]Angular - window.screen.height doesn't work on template
I have a problem when I want to optimize part of my template for mobiles in horizontal mode.当我想在水平模式下优化部分手机模板时遇到问题。
TS: TS:
window = window;
Template:模板:
<div [ngStyle]="{'height': window.innerHeight < window.innerWidth ?
window.screen.height : (widget == 'playlist' ? '334px' : '275px')}">
</div>
I'm getting nothing from window.screen.height but when I log it, it's returning good values.我从 window.screen.height 什么也没得到,但是当我记录它时,它返回了很好的值。 I was trying to use it like value but the result was the same.
我试图像价值一样使用它,但结果是一样的。
I think you are not telling your style height
what size unit it should get.我认为你没有告诉你的风格
height
它应该得到什么尺寸单位。 Pixels px
, Percentage %
, etc. I added the pixel unit as an example this:像素
px
,百分比%
等。我添加了像素单位作为示例:
<div [ngStyle]="{'height': window.innerHeight < window.innerWidth ?
window.screen.height + 'px' : (widget == 'playlist' ? '334px' : '275px')}">
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.