MCPcopy Create free account
hub / github.com/angular/angular / detectChanges

Function detectChanges

packages/core/testing/src/fixture.ts:132–160  ·  view source on GitHub ↗

* Trigger a change detection cycle for the component.

(checkNoChanges = true)

Source from the content-addressed store, hash-verified

130 * Trigger a change detection cycle for the component.
131 */
132 detectChanges(checkNoChanges = true): void {
133 const originalCheckNoChanges = (this.changeDetectorRef as InternalViewRef<unknown>)
134 .checkNoChanges;
135 try {
136 if (!checkNoChanges) {
137 (this.changeDetectorRef as InternalViewRef<unknown>).checkNoChanges = () => {};
138 }
139
140 if (this.zonelessEnabled) {
141 try {
142 this._testAppRef.includeAllTestViews = true;
143 this._appRef.tick();
144 } finally {
145 this._testAppRef.includeAllTestViews = false;
146 }
147 } else {
148 // Run the change detection inside the NgZone so that any async tasks as part of the change
149 // detection are captured by the zone and can be waited for in isStable.
150 this._ngZone.run(() => {
151 // Flush root effects before `detectChanges()`, to emulate the sequencing of `tick()`.
152 this.rootEffectScheduler.flush();
153 this.changeDetectorRef.detectChanges();
154 this.checkNoChanges();
155 });
156 }
157 } finally {
158 (this.changeDetectorRef as InternalViewRef<unknown>).checkNoChanges = originalCheckNoChanges;
159 }
160 }
161
162 /**
163 * Do a change detection run to make sure there were no changes.

Callers 1

setupInputsMethod · 0.50

Calls 5

checkNoChangesMethod · 0.80
tickMethod · 0.65
runMethod · 0.65
flushMethod · 0.45
detectChangesMethod · 0.45

Tested by

no test coverage detected