I'm looking to dynamically change the style of my HTML element based on screen size, similar to this example:
<p [ngStyle]="{'color': isMobile() ? 'red' : 'blue'}">Lorem Ipsum</p>
The code above triggers a method in my component.ts
.
isMobile() {
return window.innerWidth < 640;
}
However, it seems like this function only executes when I click somewhere on the window, not while resizing. How can I make it update instantly as the window size changes?