Git Product home page Git Product logo

mutation-observer's Introduction



Attention! This repository is archived and the library has been moved to tinkoff/ng-web-apis monorepository



ng-web-apis logo Mutation Observer API for Angular

Part of Web APIs for Angular

npm version npm bundle size Travis (.com) Coveralls github 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

Open-source

Do you also want to open-source something, but hate the collateral work? Check out this Angular Open-source Library Starter we’ve created for our projects. It got you covered on continuous integration, pre-commit checks, linting, versioning + changelog, code coverage and all that jazz.

mutation-observer's People

Contributors

marsibarsi avatar waterplea avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.