Last active
February 5, 2021 13:49
-
-
Save NetanelBasal/a74d6032ba55dcc4610f6cbfaaa946da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const breakpoints = { | |
xSmall: '(max-width: 599px)', | |
small: '(min-width: 600px) and (max-width: 959px)', | |
medium: '(min-width: 960px) and (max-width: 1279px)', | |
large: '(min-width: 1280px) and (max-width: 1919px)', | |
xLarge: '(min-width: 1920px)', | |
}; | |
@Directive({ | |
selector: '[matches]' | |
}) | |
export class MatchesDirective implements OnInit { | |
@Input() matches: keyof typeof breakpoints; | |
constructor(private tpl: TemplateRef<any> | |
private vcr: ViewContainerRef) { | |
} | |
ngOnInit() { | |
const breakpoint = breakpoints[this.matches]; | |
if (matchMedia(breakpoint).matches) { | |
this.vcr.createEmbeddedView(this.tpl); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment