1.0.2 • Published 5 years ago

ng-browser-agent v1.0.2

Weekly downloads
24
License
MIT
Repository
github
Last release
5 years ago

Ng Browser Agent

Simple Angular 10+ library to detect browser agent

Installation

Install the library using the command

$ npm i ng-browser-agent --save

Usage

Import DeviceDetectorModule in your app.module.ts

  import { NgModule } from '@angular/core';
  import { NgBrowserAgentModule } from 'ng-browser-agent';
  ...
  @NgModule({
    declarations: [
      ...
      LoginComponent,
      SignupComponent
      ...
    ],
    imports: [
      CommonModule,
      FormsModule,
      NgBrowserAgentModule // <-----
      // use DeviceDetectorModule.forRoot() for Angular v7 and below
    ],
    providers:[
      AuthService
    ]
    ...
  })

In your component where you want to use the Service, inject it

import { Component } from '@angular/core';
import { NgBrowserAgentModule } from 'ng-browser-agent';
  ...
  @Component({
    selector: 'home', 
    styleUrls: [ './home.component.scss' ],
    templateUrl: './home.component.html',
    ...
  })
 
  export class HomeComponent {

    constructor( private browserAgentService: NgBrowserAgentService) {
      this.getBrowserInformation();
    }
    
    getBrowserInformation() {
      console.log(this.browserAgentService.getBrowserName());
      console.log(this.browserAgentService.getBrowserOperatingSystem());
      console.log(this.browserAgentService.isGoogleChrome());
      console.log(this.browserAgentService.isMobile());
      console.log(this.browserAgentService.isTablet());
      console.log(this.browserAgentService.isDesktopDevice());
    }
    
  }

Methods

  1. getBrowserName()
  2. getBrowserOperatingSystem()
  3. isGoogleChrome()
  4. isMobile()
  5. isTablet()
  6. isDesktopDevice()
1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.1

5 years ago