项目作者: alshoja

项目描述 :
NPM-Library-Package, Detect your screen size change for different devices Angular- 9+
高级语言: HTML
项目地址: git://github.com/alshoja/angular-breakpoint-observer-library.git
创建时间: 2020-05-21T07:01:57Z
项目社区:https://github.com/alshoja/angular-breakpoint-observer-library

开源协议:GNU General Public License v3.0

下载


@alshoja/break-point-observer">npm version

Angular-breakpoint-observer

Let you observe your current screen size dynamicaly as observable in any of the components using the service

  • Can be used instead of media query in Angular- 9+

  • Demo in Stack Blitz

Getting started

Install via npm

  1. npm install @alshoja/break-point-observer

Import the module

  1. import { BreakPointObserverModule } from '@alshoja/break-point-observer';
  2. ............................................................................
  3. @NgModule({
  4. declarations: [
  5. AppComponent
  6. ],
  7. imports: [
  8. BrowserModule,
  9. BreakPointObserverModule.forRoot(
  10. [
  11. { gridName: 'xl', width: '(min-width: 1200px)' },
  12. { gridName: 'lg', width: '(min-width: 992px)' },
  13. { gridName: 'md', width: '(min-width: 768px)' },
  14. { gridName: 'sm', width: '(min-width: 576px)' },
  15. { gridName: 'xs', width: '(min-width: 0px)' },
  16. ]
  17. )
  18. ],
  19. providers: [],
  20. bootstrap: [AppComponent]
  21. })

Subscribe to the screen size

  1. import { BreakPointObserverService } from '@alshoja/break-point-observer';
  2. import { Component, OnInit } from '@angular/core';
  3. @Component({
  4. selector: 'app-root',
  5. templateUrl: './app.component.html',
  6. styleUrls: ['./app.component.css']
  7. })
  8. export class AppComponent implements OnInit {
  9. title = 'breaktest';
  10. constructor(private observerService: BreakPointObserverService) {
  11. }
  12. ngOnInit() {
  13. this.observerService.size.subscribe(screensize => {
  14. console.log('screensize', screensize);
  15. });
  16. }
  17. }

Running the demo app

  1. ng serve