Last active
May 8, 2020 06:01
-
-
Save yokoishioka/9f099a9b725ae2ca729514d06899c557 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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