angular-device-information
Dependencies
Angular-device-information 1.0.0 is available for Angular 9.x to Angular 13.x
Installation
To install this library, run:
$ npm install angular-device-information --save
In your app.module.ts file add AngularDeviceInformationService as providers(Optional)
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { AngularDeviceInformationService } from 'angular-device-information';
@NgModule({
imports: [ BrowserModule, FormsModule ],
providers:[AngularDeviceInformationService],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
In your component where you want to use the Device Service
import { Component } from '@angular/core';
...
import { AngularDeviceInformationService } from 'angular-device-information';
...
@Component({
selector: 'home',
styleUrls: [ './home.component.scss' ],
templateUrl: './home.component.html',
...
})
export class HomeComponent {
constructor(private deviceInformationService: AngularDeviceInformationService) {
console.log(deviceInformationService.isMobile());
console.log(deviceInformationService.isTablet());
console.log(deviceInformationService.isDesktop());
console.log(deviceInformationService.getDeviceType());
console.log(deviceInformationService.getDeviceInfo().os);
console.log(deviceInformationService.getDeviceInfo().osVersion);
console.log(deviceInformationService.getDeviceInfo().browser);
console.log(deviceInformationService.getDeviceInfo().browserVersion);
console.log(deviceInformationService.getDeviceInfo().browserMajorVersion);
console.log(deviceInformationService.getDeviceInfo().screen_resolution);
console.log(deviceInformationService.getDeviceInfo().cookies);
console.log(deviceInformationService.getDeviceInfo().userAgent);
}
}
License
MIT