Skip to content

Instantly share code, notes, and snippets.

@yokoishioka
Created May 8, 2020 06:02
Show Gist options
  • Save yokoishioka/45685c16f8f286853e5d0376a7119c20 to your computer and use it in GitHub Desktop.
Save yokoishioka/45685c16f8f286853e5d0376a7119c20 to your computer and use it in GitHub Desktop.
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