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

Method ngOnChanges

packages/forms/src/directives/ng_model.ts:265–308  ·  view source on GitHub ↗

@docs-private

(changes: SimpleChanges)

Source from the content-addressed store, hash-verified

263
264 /** @docs-private */
265 ngOnChanges(changes: SimpleChanges) {
266 if (
267 !this._registered &&
268 (typeof ngDevMode === 'undefined' || ngDevMode) &&
269 this._parent === null &&
270 !this.options?.standalone
271 ) {
272 const parentContainer = this._ngModelInjector?.get(ControlContainer, null);
273 if (parentContainer != null) {
274 const typeName =
275 parentContainer instanceof NgForm
276 ? 'NgForm'
277 : parentContainer instanceof FormGroupDirective
278 ? 'FormGroupDirective'
279 : parentContainer instanceof NgModelGroup
280 ? 'NgModelGroup'
281 : parentContainer.constructor.name || 'ControlContainer';
282 console.warn(ngModelInChildComponentWarning(typeName));
283 }
284 }
285 this._checkForErrors();
286 if (!this._registered || 'name' in changes) {
287 if (this._registered) {
288 this._checkName();
289 if (this.formDirective) {
290 // We can't call `formDirective.removeControl(this)`, because the `name` has already been
291 // changed. We also can't reset the name temporarily since the logic in `removeControl`
292 // is inside a promise and it won't run immediately. We work around it by giving it an
293 // object with the same shape instead.
294 const oldName = changes['name'].previousValue;
295 this.formDirective.removeControl({name: oldName, path: this._getPath(oldName)});
296 }
297 }
298 this._setUpControl();
299 }
300 if ('isDisabled' in changes) {
301 this._updateDisabled(changes);
302 }
303
304 if (isPropertyUpdated(changes, this.viewModel)) {
305 this._updateValue(this.model);
306 this.viewModel = this.model;
307 }
308 }
309
310 /** @docs-private */
311 ngOnDestroy(): void {

Callers

nothing calls this directly

Calls 11

_checkForErrorsMethod · 0.95
_checkNameMethod · 0.95
_getPathMethod · 0.95
_setUpControlMethod · 0.95
_updateDisabledMethod · 0.95
_updateValueMethod · 0.95
isPropertyUpdatedFunction · 0.90
getMethod · 0.65
warnMethod · 0.65
removeControlMethod · 0.65

Tested by

no test coverage detected