MCPcopy Index your code
hub / github.com/angular/angular / ngControlCreate

Function ngControlCreate

packages/forms/src/directives/ng_control.ts:215–248  ·  view source on GitHub ↗

* Internal control directive creation lifecycle hook. * * The presence of this method tells the compiler to install `ɵɵControlFeature`, which will * cause this directive to be recognized as a control directive by the `ɵcontrolCreate` and * `ɵcontrol` instructions. * * @internal

(host: ControlDirectiveHost)

Source from the content-addressed store, hash-verified

213 * @internal
214 */
215 protected ngControlCreate(host: ControlDirectiveHost): void {
216 const hasNgNoCva = host.nativeElement.hasAttribute?.('ngNoCva');
217 const hasCva =
218 !hasNgNoCva &&
219 ((this.rawValueAccessors && this.rawValueAccessors.length > 0) ||
220 this.valueAccessor !== null);
221
222 if (hasCva || !host.customControl) {
223 // This control is using the CVA pattern, so ngControlCreate is a noop.
224 return;
225 }
226
227 this.isCustomControlBased = true;
228
229 // Listen to custom control value changes -> update FormControl
230 // Note: We access this.control dynamically because it may not be set yet
231 // (e.g., FormControlDirective's form input hasn't been bound)
232 host.listenToCustomControlModel((value) => {
233 // TODO: is there a case where this input has not yet been set?
234 this.control?.setValue(value, {emitModelToViewChange: false});
235 this.control?.markAsDirty();
236 this.viewToModelUpdate(value);
237 });
238
239 // Listen to touched changes from FVC
240 host.listenToCustomControlOutput('touch', () => {
241 this.control?.markAsTouched();
242 });
243
244 this.customControlBindings = {};
245 this.isNativeFormElement = isNativeFormElement(host.nativeElement);
246
247 this.requiredValidatorViaDi = this._rawValidators.find((v) => v instanceof RequiredValidator);
248 }
249
250 protected ngControlUpdate(host: ControlDirectiveHost, bindRequired: boolean): void {
251 if (!this.isCustomControlBased) {

Callers

nothing calls this directly

Calls 9

isNativeFormElementFunction · 0.90
hasAttributeMethod · 0.80
setValueMethod · 0.65
markAsDirtyMethod · 0.65
markAsTouchedMethod · 0.65
viewToModelUpdateMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…