4.11.1 • Published 7 months ago

@ng-web-apis/resize-observer v4.11.1

Weekly downloads
643
License
Apache-2.0
Repository
github
Last release
7 months ago

ng-web-apis logo Resize Observer API for Angular

npm version npm bundle size codecov

This is a library for declarative use of Resize Observer API with Angular.

Install

If you do not have @ng-web-apis/common:

npm i @ng-web-apis/common

Now install the package:

npm i @ng-web-apis/resize-observer

Usage

  1. Import ResizeObserverModule to the module where you plan to use it.
  2. Use waResizeObserver directive to observe an element:
<section>
  <h1
    waResizeBox="content-box"
    (waResizeObserver)="onResize($event)"
  >
    I'm being observed
  </h1>
</section>

Use waResizeBox to configure ResizeObserver options

NOTE: Keep in mind these are used one time in constructor so you cannot use binding, only strings.

Service

Alternatively you can use Observable-based ResizeObserverService and provide token RESIZE_OPTION_BOX manually:

@Component({
  selector: 'my-component',
  providers: [
    ResizeObserverService,
    {
      provide: RESIZE_OPTION_BOX,
      useValue: 'border-box',
    },
  ],
})
export class Example {
  constructor(@Inject(ResizeObserverService) entries$: ResizeObserverService) {
    entries$.subscribe((entries) => {
      // This will trigger when the component resizes
      // Don't forget to unsubscribe
      console.log(entries);
    });
  }
}

Browser support

79+69+64+13.1+13.4+

You can use polyfill to support older browsers

Demo

You can try online demo here

See also

Other Web APIs for Angular by @ng-web-apis

4.11.0

7 months ago

4.11.1

7 months ago

4.9.0

7 months ago

4.8.0

7 months ago

4.6.5

8 months ago

4.7.0

7 months ago

4.10.1

7 months ago

4.10.2

7 months ago

4.10.0

7 months ago

4.6.4

8 months ago

4.6.3

8 months ago

4.6.2

8 months ago

4.6.1

8 months ago

4.6.0

8 months ago

4.5.1

8 months ago

4.5.0

8 months ago

4.3.0

8 months ago

3.2.2

10 months ago

3.2.1

11 months ago

3.2.3

10 months ago

4.1.3

10 months ago

4.1.0

11 months ago

4.0.1

11 months ago

4.0.0

11 months ago

4.2.1

10 months ago

4.1.2

11 months ago

4.2.0

10 months ago

4.1.1

11 months ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.6

2 years ago

3.0.5

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.1.0

2 years ago

2.0.0

3 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago