I have a solution, I just donβt know if this is better. I had a similar problem, but I solved it.
I have a variable that says it is open or closed (menuOpen) only changes between true and false, and a variable with three states: 0 or 1 or 2 (onOpen) I have three states, you see it here.
import { Component, trigger, state, animate, transition, style, HostListener} from '@angular/core' .... .... animations: [ trigger('visibilityChanged', [ state('0', style({ width: '50px' })), state('1', style({ width: '25%' })), state('2', style({ width: '100%' })), transition('* => *', animate('.3s')) ]) ]....
You can do one function for permission, I am in what I did not
export class AppComponent { wt; @HostListener('window:resize', ['$event']) sizeWindow(event) { this.wt = event.target.innerWidth; this.sizeMenu(this.wt); console.log('width =>', this.wt); } constructor() { this.wt = window.innerWidth; } sizeMenu(width) { if (this.menuOpen === true) { if (width >= 600) { this.onTestOpen = 1; } else if (width < 600) { this.onTestOpen = 2; } } else if (this.menuOpen === false) { this.onTestOpen = 0; } } openMenu() { let wwt = window.innerWidth; if (this.menuOpen === false) { if (wwt >= 600) { this.onTestOpen = 1; } else if (wwt < 600) { this.onTestOpen = 2; } this.menuOpen = true; } else if (this.menuOpen === true) { this.onTestOpen = 0; this.menuOpen = false; } } }
in my template i have it
<div class="geral" [@visibilityChanged]="onOpen"></div>
I think in your case you have to deal with a lot of conditions.
Ketty miilher
source share