项目作者: reactgular

项目描述 :
Angular library that simplifies working with desktop, tablet and mobile devices.
高级语言: TypeScript
项目地址: git://github.com/reactgular/devices.git
创建时间: 2019-12-09T13:45:14Z
项目社区:https://github.com/reactgular/devices

开源协议:

下载


Build Status
Coverage Status
npm version

Devices

Devices is an Angular library that wraps around the BreakpointObserver
utility provided by the Angular Material CDK library.

Overview

Angular Material CDK library provides a BreakpointObserver utility
which emits state changes based upon screen and orientation of
the web browser. The problem with this library is that the matching
rules are broad in scope, and most developers just want to
know what device the user is using.

This library simplifies the business logic of responding to changes in
screen sizes and orientation.

Install

To get started, install the package from npm.

  1. npm install @reactgular/devices

Once installed you need to import the DevicesModule module into your project.

  1. import {DevicesModule} from '@reactgular/devices';
  2. @NgModule({
  3. ...
  4. imports: [DevicesModule, ...],
  5. ...
  6. })
  7. export class AppModule {
  8. }

Usage

You can use the DevicesService in your components or services by
injecting the service. There are a number of observable properties that
emit values relative to the type of device or orientation.

These properties of the service just make it easier to work with changes
to the device screen.

  1. import {DevicesService} from '@reactgular/devices';
  2. @Component({
  3. selector: 'app-example',
  4. template: `
  5. <div *ngIf="web$ | async">Web only</div>
  6. <div *ngIf="tablet$ | async">Tablet only</div>
  7. <div *ngIf="handset$ | async">Handset only</div>
  8. `
  9. })
  10. export class ExampleComponent {
  11. public web$: Observable<boolean>;
  12. public table$: Observable<boolean>;
  13. public handset$: Observable<boolean>;
  14. public constructor(devices: DevicesService) {
  15. this.web$ = devices.web$;
  16. this.tablet$ = devices.tablet$;
  17. this.handset$ = devices.handset$;
  18. }
  19. }

Getting help

You are welcome to open issues for general support questions as well as bug reports and feature requests.