Is there a way I can streamline my if/else
statement to avoid code repetition in my header component? Take a look at the example below:
export class HeaderMainComponent {
logoAlt = 'We Craft beautiful websites'; // Logo alt and title texts
@ViewChild('navTrigger') navTrigger: ElementRef;
isMenuShown: false;
constructor(private layoutService: LayoutService, private renderer) { }
menuToggle(event: any) {
this.toggleNavClass();
}
onMenuSelect(event: any) {
this.isMenuShown = false;
this.toggleNavClass();
}
private toggleNavClass() {
if (this.navTrigger.nativeElement.classList.contains('opened')) {
this.navTrigger.nativeElement.classList.remove('opened');
} else {
this.navTrigger.nativeElement.classList.add('opened');
}
}
}