Skip to content
Snippets Groups Projects
device.service.ts 587 B
Newer Older
import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class DeviceService {
  hasHardwareKeyboard: boolean = false;
  private readonly isTouch!: boolean;
  private readonly isMobile!: boolean;
    this.isTouch = ('ontouchstart' in window) || (navigator && navigator.maxTouchPoints > 0);
    this.isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);

  get isMobileWithoutHardwareKeyboard(): boolean {
    return this.isMobile && this.isTouch && !this.hasHardwareKeyboard;