MCPcopy Create free account
hub / github.com/angular/components / _observeElement

Method _observeElement

src/cdk/observers/observe-content.ts:125–143  ·  view source on GitHub ↗

* Observes the given element by using the existing MutationObserver if available, or creating a * new one if not.

(element: Element)

Source from the content-addressed store, hash-verified

123 * new one if not.
124 */
125 private _observeElement(element: Element): Subject<MutationRecord[]> {
126 return this._ngZone.runOutsideAngular(() => {
127 if (!this._observedElements.has(element)) {
128 const stream = new Subject<MutationRecord[]>();
129 const observer = this._mutationObserverFactory.create(mutations => stream.next(mutations));
130 if (observer) {
131 observer.observe(element, {
132 characterData: true,
133 childList: true,
134 subtree: true,
135 });
136 }
137 this._observedElements.set(element, {observer, stream, count: 1});
138 } else {
139 this._observedElements.get(element)!.count++;
140 }
141 return this._observedElements.get(element)!.stream;
142 });
143 }
144
145 /**
146 * Un-observes the given element and cleans up the underlying MutationObserver if nobody else is

Callers 1

observeMethod · 0.95

Calls 5

setMethod · 0.80
getMethod · 0.65
createMethod · 0.45
nextMethod · 0.45
observeMethod · 0.45

Tested by

no test coverage detected