Angular (6+) directives for native observers API for detecting element's size change, visibility and DOM manipulations.
Giving you
onResize()
,onMutate()
andonIntersection()
using ResizeObserver, MutationObserver and IntersectionObserver.
npm i ng-observers
Then import NgObserversModule
:
import { NgObserversModule } from 'ng-observers';
@NgModule({
declarations: [AppComponent],
imports: [NgObserversModule],
bootstrap: [AppComponent]
})
export class AppModule {}
<div resizeObserver (onResize)="onResize($event)"></div>
<div intersectionObserver (onIntersection)="onIntersection($event)"></div>
<div mutationObserver (onMutate)="onMutate($event)"></div>
class AppComponent {
onResize(event) {
// ...
}
onIntersection(event) {
// ...
}
onMutate(event) {
// ...
}
}
<div mutationObserver
[options]="{attributes: true, subtree: true}"
(onMutate)="onMutate($event)"></div>
options
is optional, structured as MutationObserverInit:
options = {
childList: false,
attributes: true,
subtree: false,
characterData: true
}