Hello I have 4 different components that use the same browser listening logic I've implemented like here:
@Component(...)
export class FooComponent {
k = false;
@HostListener('window:resize', ['$event'])
onResize(event) {
if (window.innerWidth <= 768) {
this.k = true;
} else if (window.innerWidth > 768) {
this.k = false;
}
}
}
Which corresponds to the HTML component here:
<button
[ngClass]="k ? 'mdc-fab--mini' : 'mdc-fab--extended'"
class="mdc-fab mdc-fab--touch"
(click)="openQr()"
>
Foo Button
</button>
If k
is true , the class 'mdc-fab--mini'
should be applied and vice-versa.
When I resize the browser screen it works as intended, but the moment I route to another component with this same lines of code (HTML and the typescript logic), the class 'mdc-fab--mini'
is not applied and instead the 'mdc-fab--extended'
is applied even though the browser window is less than 768px
.
Is there a reason for this?