@ng-web-apis/mutation-observer
TypeScript icon, indicating that this package has built-in type declarations

3.1.0 • Public • Published

ng-web-apis logo Mutation Observer API for Angular

Part of > Web APIs for Angular

npm version npm bundle size Travis (.com) codecov angular-open-source-starter

This is a library for declarative use of Mutation 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/mutation-observer

Usage

Add MutationObserverModule and then use (waMutationObserver)="onMutation($event)" directive to watch mutation in an element.

Alternatively use an Observable-based MutationObserverService manually to get MutationObserver in an RxJS Observable form.

Configuring

Use attributes on an element to define MutationObserverInit config object. All attributes are boolean meaning no need to explicitly set them to true.

NOTE: Keep in mind these are used one time in constructor so you cannot use binding, only strings. Pass comma separated attribute names to set attributeFilter array.

Example

<div
  subtree
  childList
  characterData
  attributeFilter="title, aria-label"
  [title]="title"
  [attr.aria-label]="label"
  (waMutationObserver)="onMutation($event)"
>
  ...
</div>

Browser support

IE / Edge Firefox Chrome Safari
11+ 14+ 26+ 7+

Angular Universal

If you want to use this package with SSR, you need to mock MutationObserver class on the server. You can use our Universal package for this, see this example.

Demo

You can try online demo here

See also

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

/@ng-web-apis/mutation-observer/

    Package Sidebar

    Install

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

    Weekly Downloads

    5,221

    Version

    3.1.0

    License

    Apache-2.0

    Unpacked Size

    145 kB

    Total Files

    24

    Last publish

    Collaborators

    • marsibarsi
    • waterplea
    • vladimir.potekhin
    • defenderbass