Is there any way of showing an element based on some Directive?
const CUSTOM_BREAKPOINTS = {
small: '(max-width: 1999px)'
};
@Directive({
selector: '[appResponsive]',
standalone: true,
host: {
'[class.mobile]': 'isMobile'
}
})
export class MobileClassDirective implements OnDestroy {
isMobile = false;
private destroy$ = new Subject<void>();
constructor(private breakpointObserver: BreakpointObserver) {
this.breakpointObserver
.observe([CUSTOM_BREAKPOINTS.small])
.pipe(takeUntil(this.destroy$))
.subscribe(result => {
this.isMobile = result.matches;
});
}
ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
}
// HTML
<div class="taglist-search" appResponsive> // Dynamic class added properly based on viewport
@if (!appResponsive.isMobile) {<ng-container *ngTemplateOutlet="taglist"></ng-container>} // doesn't work ofc, but is there any way to get a similar behaviour?