17.0.0 • Published 1 year ago

angular-container-media-query v17.0.0

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

AngularContainerMediaQuery

Container or Component media queries for Angular.

@Component({
  selector: 'app-parent',
  template: `<app-child></app-child>`,
})
class ParentComponent {}

@Component({selector: 'app-child'})
class ChildComponent implements AfterViewInit {
  // when the app-parent width is below 20rem the foo class is added
  @MediaQuery('app-parent:(max-width: 20rem)') @HostBinding('class.foo') foo = false;
  // you can also select any direct parent with the `$parent` selector (in this case `app-parent`)
  @MediaQuery('$parent:(max-width: 20rem)') @HostBinding('class.bar') bar = false;
  // when the app-child width is below 20rem the bas class is added
  @MediaQuery('(max-width: 20rem)') @HostBinding('class.bas') bas = false;

  constructor(
    private _resize: ObserveResizeService,
    private _elementRef: ElementRef,
    private _changeDetector: ChangeDetectorRef
  ) {}

  ngAfterViewInit(): void {
    this._resize.register(this, this._elementRef, this._changeDetector);
  }
}

In app-parent:(max-width: 20rem) the selector part app-parent is used to find the closest parent in the DOM tree, the size changes of that parent are observed and used to check the MediaQuery part (max-width: 20rem).

supported media features:

  • min-width
  • max-width
  • min-height
  • max-height

the and operator is also supported e.g. (min-width: 200px) and (max-width: 400px)

17.0.0

1 year ago

16.0.0

1 year ago

15.0.0

2 years ago

14.2.10

2 years ago

13.1.1

3 years ago

13.1.0-next.3

4 years ago

13.0.4

4 years ago

13.0.3

4 years ago

12.2.13

4 years ago

7.0.0

4 years ago

6.0.0

4 years ago

5.0.1

4 years ago

5.0.0

4 years ago

1.0.2

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.0.0

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.1

4 years ago

0.0.1

4 years ago

1.0.0

4 years ago

0.0.0

4 years ago