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

Method ngDoCheck

packages/common/src/directives/ng_for_of.ts:253–284  ·  view source on GitHub ↗

* Applies the changes when needed. * @docs-private

()

Source from the content-addressed store, hash-verified

251 * @docs-private
252 */
253 ngDoCheck(): void {
254 if (this._ngForOfDirty) {
255 this._ngForOfDirty = false;
256 // React on ngForOf changes only once all inputs have been initialized
257 const value = this._ngForOf;
258 if (!this._differ && value) {
259 if (typeof ngDevMode === 'undefined' || ngDevMode) {
260 try {
261 // CAUTION: this logic is duplicated for production mode below, as the try-catch
262 // is only present in development builds.
263 this._differ = this._differs.find(value).create(this.ngForTrackBy);
264 } catch {
265 let errorMessage =
266 `Cannot find a differ supporting object '${value}' of type '` +
267 `${getTypeName(value)}'. NgFor only supports binding to Iterables, such as Arrays.`;
268 if (typeof value === 'object') {
269 errorMessage += ' Did you mean to use the keyvalue pipe?';
270 }
271 throw new RuntimeError(RuntimeErrorCode.NG_FOR_MISSING_DIFFER, errorMessage);
272 }
273 } else {
274 // CAUTION: this logic is duplicated for development mode above, as the try-catch
275 // is only present in development builds.
276 this._differ = this._differs.find(value).create(this.ngForTrackBy);
277 }
278 }
279 }
280 if (this._differ) {
281 const changes = this._differ.diff(this._ngForOf);
282 if (changes) this._applyChanges(changes);
283 }
284 }
285
286 private _applyChanges(changes: IterableChanges<T>) {
287 const viewContainer = this._viewContainer;

Callers

nothing calls this directly

Calls 5

_applyChangesMethod · 0.95
getTypeNameFunction · 0.70
createMethod · 0.65
diffMethod · 0.65
findMethod · 0.45

Tested by

no test coverage detected