Skip to content

Instantly share code, notes, and snippets.

@yokoishioka
Last active May 8, 2020 06:01
Show Gist options
  • Save yokoishioka/9f099a9b725ae2ca729514d06899c557 to your computer and use it in GitHub Desktop.
Save yokoishioka/9f099a9b725ae2ca729514d06899c557 to your computer and use it in GitHub Desktop.
import { Directive, HostListener } from '@angular/core';
import { DevicesService } from './devices.service';
@Directive({
selector: '[cesDeviceScreenSize]'
})
export class DeviceScreenSizeDirective {
constructor(
private devices: DevicesService
) { }
@HostListener('window:load', ['$event']) onLoad(event) {
this.sendSize(event.currentTarget.innerWidth);
}
@HostListener('window:resize', ['$event']) onResize(event) {
this.sendSize(event.currentTarget.innerWidth);
}
sendSize(width: number) {
this.devices.setSize(width);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment