Angular - issue with getting window.screen.height in template

One issue I'm facing is when attempting to optimize a section of my template for mobile devices in landscape mode.

TS:

window = window;

Template:

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

Despite logging good values for window.screen.height, I'm not getting any output from it. I tried using it as a value, but the result remained the same.

Answer №1

It seems like you forgot to specify the unit for the style property height. You can use pixels px, percentage %, or other units. For example, I have added the pixel unit in this code snippet:

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Clear backdrop with solid objects

I am trying to achieve a unique design where the body has an image background, and the main div has a semitransparent background. I want the image to be visible through the main div, but in a shaded manner. However, the traditional approach may cause every ...

Modify the background color of column headers in a Material UI DataGrid as you scroll down vertically

In my React(NextJS) project using material UI, I have implemented tables (DataGrid component from material UI) with distinct background colors in the column headers, as shown below: https://i.sstatic.net/zd3Iu.png However, I encountered an issue where ra ...

Creating a spinning Cube with separate fields for x, y, and z rotation speeds: a step-by-step guide

After dabbling in Java, Visual Basic, HTML, and CSS, I'm now looking to create an interface featuring a central spinning cube with 3 fields to control its x, y, and z rotation speeds. Can you suggest which language would be the best fit for this proje ...

Why is Angular ng-block-ui not functioning properly in Angular 7?

Within my app.module.ts file import { BlockUIModule } from 'ng-block-ui'; imports: [ BrowserModule, BlockUIModule.forRoot(), ] Inside the dashboard component: import { BlockUI, NgBlockUI } from 'ng-block-ui'; export class Da ...

Ways to continuously monitor a div for a specific class

Is there a way to continuously check if an area has the class "top-nav" in order for the alerts to work every time it lacks or contains the class? How can I achieve this functionality? Check out the code on jsfiddle: https://jsfiddle.net/jzhang172/117mg0y ...

Bootstrap 4 experiences issues with modal dialogs

I am experiencing an issue with my code not working on Bootstrap 4. When I click on the 'overview' button, the page darkens but the dialog does not appear. This functionality worked fine with the old version of Bootstrap. Can someone please assis ...

Applying Multiple Conditions to setCellProps in Material-UI

I am facing an issue with a data-table that is not in a class extending the React.Component, unlike some examples I have come across. My goal is to setCellProps based on certain conditions as outlined below: If utilization is less than or equal to 50, the ...

Angular - Detecting Scroll Events on Page Scrolling Only

I am currently working on implementing a "show more" feature and need to monitor the scroll event for this purpose. The code I am using is: window.addEventListener('scroll', this.scroll, true); Here is the scroll function: scroll = (event: any) ...

Java - openpdf - Splitting words using hyphens

We are currently utilizing openpdf 1.3.26 template 2.1 to create PDFs from HTML and CSS. Within our coding, there is a div element styled as follows: .text-block{ display:block; text-align:justify; word-wrap: break-word; ...

Monitoring changes in a variable's value within an Angular 6 component

Within a page component, there exists an array; The array has new elements added to it in different locations within the component (in the createMessage() method and inside the subscriber of getIncomingMessagesStream()); Each time a new element is added to ...

Issue with setInterval function execution within an Angular for loop

My goal is to dynamically invoke an API at specific intervals. However, when attempting to utilize the following code snippet in Angular 7, I encountered issues with the interval timing. I am seeking a solution for achieving dynamic short polling. ngOnIn ...

Ways to prevent a centered list from shifting to the right

Although this question has appeared before, I am facing an issue with a list displayed as an inline block for use as a navigation bar. My goal is to center the nav bar on the webpage and ensure it scales down appropriately. <ul class="nav_bar"> ...

Position elements flush to the left and right

Is it possible to align the text in divs so that it perfectly lines up along the edges? .name { margin: 0 0 5px 10px; font-weight: bold; font-size: 14px; } .row { margin: 0 0 5px 10px; width: 500px; justify-content: space-between; } < ...

Utilizing background images in CSS to enhance bootstrap icons

Here is the HTML code snippet I'm working with: <a class="iconContainer" href="#"> <span class="containerIcon chevron-right"/> Test </a> And this is the corresponding CSS code: .chevron-right::befor ...

Removing a value from an array of objects in Angular 2

There is a single array that holds objects: one = [ {name: 'Name', key: '4868466'}, {name: 'Name', key: '4868466'}, {name: 'Name', key: '4868466'}, {name: 'Name', key: & ...

Angular attribute directive encountered an error during production build, where it was expected to receive 1 argument but instead received

I have been working on a large-scale application that has been developed by multiple teams over an extended period. A frontend developer from another location included a significant amount of repetitive imperative code, utilizing jQuery for DOM manipulati ...

Scrolling the inner div with the main scrollbar before navigating through the rest of the page

In my hero div, I have a container div called right-col that contains two inner divs. These inner divs are sticky, creating the effect of cards sliding up when the container div is scrolled. This is the HTML structure: <!DOCTYPE html> <html lang= ...

What could be causing my anchored link to redirect incorrectly?

My navigation bar correctly directs me to the 'work' section, but when I click on ABOUT in the navigation bar, it drops down about 300px above the 'about' h2. I suspect that this issue may be related to positioning and display settings. ...

Transforming Ajax POST requests into Angular 8 API calls

After receiving the Ajax Post call from the client, I was able to successfully insert static data when opening the PHP API file in a browser. Now, I am attempting to utilize Angular to achieve the same result. However, I am struggling to understand how to ...

What is the best way to align a modal with a layout when it appears far down the components hierarchy?

Struggling with creating a React modal and facing some issues. Let's consider the structure below: React structure <ComponentUsingModal> <Left> <ButtonToActivateModal> ... </ButtonToActivateModa ...