Created
May 8, 2020 06:02
-
-
Save yokoishioka/45685c16f8f286853e5d0376a7119c20 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
import { Injectable, Input } from '@angular/core'; | |
import { Subject, Observable } from 'rxjs'; | |
import { ScreenSize, DetectType } from './devices'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class DevicesService { | |
screenSize: Subject<any> = new Subject(); | |
@Input() detectSize: DetectType; | |
constructor() { } | |
setSize(width: number): Observable<any> { | |
if (this.detectSize === 'number') { | |
this.screenSize.next(width); | |
} | |
else { | |
if (width < ScreenSize.medium) { | |
this.screenSize.next('small'); | |
} | |
else if (width > ScreenSize.medium) { | |
this.screenSize.next('medium'); | |
} | |
if (width > ScreenSize.large) { | |
this.screenSize.next('large'); | |
} | |
} | |
return this.screenSize; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment