UNPKG

3.88 kBTypeScriptView Raw
1import { AfterContentInit } from '@angular/core';
2import { BooleanInput } from '@angular/cdk/coercion';
3import { ElementRef } from '@angular/core';
4import { EventEmitter } from '@angular/core';
5import * as i0 from '@angular/core';
6import { NgZone } from '@angular/core';
7import { NumberInput } from '@angular/cdk/coercion';
8import { Observable } from 'rxjs';
9import { OnDestroy } from '@angular/core';
10
11/**
12 * Directive that triggers a callback whenever the content of
13 * its associated element has changed.
14 */
15export declare class CdkObserveContent implements AfterContentInit, OnDestroy {
16 private _contentObserver;
17 private _elementRef;
18 private _ngZone;
19 /** Event emitted for each change in the element's content. */
20 readonly event: EventEmitter<MutationRecord[]>;
21 /**
22 * Whether observing content is disabled. This option can be used
23 * to disconnect the underlying MutationObserver until it is needed.
24 */
25 get disabled(): boolean;
26 set disabled(value: BooleanInput);
27 private _disabled;
28 /** Debounce interval for emitting the changes. */
29 get debounce(): number;
30 set debounce(value: NumberInput);
31 private _debounce;
32 private _currentSubscription;
33 constructor(_contentObserver: ContentObserver, _elementRef: ElementRef<HTMLElement>, _ngZone: NgZone);
34 ngAfterContentInit(): void;
35 ngOnDestroy(): void;
36 private _subscribe;
37 private _unsubscribe;
38 static ɵfac: i0.ɵɵFactoryDeclaration<CdkObserveContent, never>;
39 static ɵdir: i0.ɵɵDirectiveDeclaration<CdkObserveContent, "[cdkObserveContent]", ["cdkObserveContent"], { "disabled": { "alias": "cdkObserveContentDisabled"; "required": false; }; "debounce": { "alias": "debounce"; "required": false; }; }, { "event": "cdkObserveContent"; }, never, never, false, never>;
40}
41
42/** An injectable service that allows watching elements for changes to their content. */
43export declare class ContentObserver implements OnDestroy {
44 private _mutationObserverFactory;
45 /** Keeps track of the existing MutationObservers so they can be reused. */
46 private _observedElements;
47 constructor(_mutationObserverFactory: MutationObserverFactory);
48 ngOnDestroy(): void;
49 /**
50 * Observe content changes on an element.
51 * @param element The element to observe for content changes.
52 */
53 observe(element: Element): Observable<MutationRecord[]>;
54 /**
55 * Observe content changes on an element.
56 * @param element The element to observe for content changes.
57 */
58 observe(element: ElementRef<Element>): Observable<MutationRecord[]>;
59 /**
60 * Observes the given element by using the existing MutationObserver if available, or creating a
61 * new one if not.
62 */
63 private _observeElement;
64 /**
65 * Un-observes the given element and cleans up the underlying MutationObserver if nobody else is
66 * observing this element.
67 */
68 private _unobserveElement;
69 /** Clean up the underlying MutationObserver for the specified element. */
70 private _cleanupObserver;
71 static ɵfac: i0.ɵɵFactoryDeclaration<ContentObserver, never>;
72 static ɵprov: i0.ɵɵInjectableDeclaration<ContentObserver>;
73}
74
75/**
76 * Factory that creates a new MutationObserver and allows us to stub it out in unit tests.
77 * @docs-private
78 */
79export declare class MutationObserverFactory {
80 create(callback: MutationCallback): MutationObserver | null;
81 static ɵfac: i0.ɵɵFactoryDeclaration<MutationObserverFactory, never>;
82 static ɵprov: i0.ɵɵInjectableDeclaration<MutationObserverFactory>;
83}
84
85export declare class ObserversModule {
86 static ɵfac: i0.ɵɵFactoryDeclaration<ObserversModule, never>;
87 static ɵmod: i0.ɵɵNgModuleDeclaration<ObserversModule, [typeof CdkObserveContent], never, [typeof CdkObserveContent]>;
88 static ɵinj: i0.ɵɵInjectorDeclaration<ObserversModule>;
89}
90
91export { }