in angular 9 get device with code example
Example 1: angular get device information
npm install ngx-device-detector
Example 2: angular get device information
import { Component, VERSION } from "@angular/core";
import { DeviceDetectorService } from "ngx-device-detector";
@Component({
selector: "my-app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent {
name = "Angular " + VERSION.major;
deviceInfo = null;
isDesktopDevice: boolean;
isTablet: boolean;
isMobile: boolean;
constructor(private deviceService: DeviceDetectorService) {
this.epicFunction();
}
epicFunction() {
this.deviceInfo = this.deviceService.getDeviceInfo();
this.isMobile = this.deviceService.isMobile();
this.isTablet = this.deviceService.isTablet();
this.isDesktopDevice = this.deviceService.isDesktop();
}
}