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

91
February 09, 2022, at 03:20 AM

I have a problem when I want to optimize part of my template for mobiles in horizontal mode.

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. I was trying to use it like value but the result was the same.

Answer 1

I think you are not telling your style height what size unit it should get. Pixels px, Percentage %, etc. I added the pixel unit as an example this:

 <div [ngStyle]="{'height': window.innerHeight < window.innerWidth ?
    window.screen.height + 'px' : (widget == 'playlist' ? '334px' : '275px')}">
 </div>
Rent Charter Buses Company
READ ALSO
use css variable to generate class names in scss

use css variable to generate class names in scss

is it possible to generate class names by css variables?

132
JSON Parse error: Unexpected identifier &quot;undefined&quot;

JSON Parse error: Unexpected identifier "undefined"

i just switched to a mac today and i noticed the JSONparse that works on other browsers, throws this error on safari

136
Set Integers getItemViewType RecyclerView

Set Integers getItemViewType RecyclerView

I have an array list of integers[3,-3,7,9,8,1]

116