Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {Injectable } from '@angular/core';
- @Injectable()
- export class PlatformDetectorService
- {
- private _userAgent: string;
- constructor() {
- this._userAgent = window.navigator.userAgent.toLowerCase();
- }
- public getPlatform(): string
- {
- if (this.isTablet())
- {
- return "Tablet";
- }
- else if(this.isMobile())
- {
- return "Mobile";
- }
- else
- {
- return "Desktop";
- }
- }
- // Public properties
- get UserAgent(): string
- {
- return this._userAgent;
- }
- private isTablet(): boolean
- {
- if(this._userAgent.match(/Tablet|iPad/i))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- private isMobile(): boolean
- {
- if(this._userAgent.match(/Mobile|Windows Phone|Lumia|Android|webOS|iPhone|iPod|Blackberry|PlayBook|BB10|Opera Mini|\bCrMo\/|Opera Mobi/i))
- {
- return true;
- }
- else
- {
- return false;
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement