import { Component } from '@angular/core';
...
import { AngularDeviceInformationService } from 'angular-device-information';
...
@Component({
selector: 'home', // <home></home>
styleUrls: [ './home.component.scss' ],
templateUrl: './home.component.html',
...
})
export class HomeComponent {
constructor(private deviceInformationService: AngularDeviceInformationService) {
console.log(deviceInformationService.isMobile()); // returns if the device is a mobile device (android / iPhone / windows-phone etc)
console.log(deviceInformationService.isTablet()); // returns if the device is a tablet (tablet iPad etc)
console.log(deviceInformationService.isDesktop()); // returns if the app is running on a Desktop browser.
console.log(deviceInformationService.getDeviceType()); // returns if the app is running on a Desktop browser.
console.log(deviceInformationService.getDeviceInfo().os); // returns os name like Windows/Andtoid/iOS/Linux/Mac OS X etc
console.log(deviceInformationService.getDeviceInfo().osVersion); // returns os version like 10/8.1/7 ...etc
console.log(deviceInformationService.getDeviceInfo().browser); // returns browser name like chrome/firefox ...etc
console.log(deviceInformationService.getDeviceInfo().browserVersion); // returns browser version as number
console.log(deviceInformationService.getDeviceInfo().browserMajorVersion); // returns full browser version as number
console.log(deviceInformationService.getDeviceInfo().screen_resolution); // returns screnn size like 1390x860/640x800 ...etc
console.log(deviceInformationService.getDeviceInfo().cookies); // returns cookies enabled or no
console.log(deviceInformationService.getDeviceInfo().userAgent); // returns userAgent
}
}
2条答案
按热度按时间f0brbegy1#
您可以使用,
ngx-device-detector
ngx-device-detector
是一款Angular 2
(及更高版本)支持的AOT兼容设备检测器,可帮助识别浏览器、操作系统和其他有关使用该应用程序的设备的有用信息。该处理基于用户代理。安装:
要安装此库,请运行:
用法:
在您要使用设备服务的组件中
设备服务:
包含以下属性:
gg0vcinb2#
您可以使用**angular-device-information**是一个功能强大的Angular 包来检测操作系统和版本
npm i angular-device-information