Skip to content

Instantly share code, notes, and snippets.

@NetanelBasal
Last active February 5, 2021 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NetanelBasal/a74d6032ba55dcc4610f6cbfaaa946da to your computer and use it in GitHub Desktop.
Save NetanelBasal/a74d6032ba55dcc4610f6cbfaaa946da to your computer and use it in GitHub Desktop.
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