import { WindowRef } from './window-ref-wrapper' ; import { Pipe , PipeTransform } from '@angular/core' ; @ Pipe ( { name : 'mobileCheck' } ) export class MobileCheckPipe implements PipeTransform { globalWindow : Window ; constructor ( public windowRef ) { this . globalWindow = this . windowRef . nativeWindow ; } transform ( ) { let isMobile = false ; if ( this . globalWindow ) { try { const str = this . globalWindow . navigator . userAgent || this . globalWindow . navigator . vendor ; isMobile = str . match ( /(Android|webOS|iPhone|iPad|iPod|BlackBerry)/i ) !== null || str . match ( /(Windows Phone|iemobile|WPDesktop)/i ) !== null ; } catch ( e ) { return false ; } } return isMobile ; } }