1.0.2 • Published 5 years ago
ng-browser-agent v1.0.2
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
- getBrowserName()
- getBrowserOperatingSystem()
- isGoogleChrome()
- isMobile()
- isTablet()
- isDesktopDevice()