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

Method constructor

src/material/input/input.ts:298–360  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

296 ].filter(t => getSupportedInputTypes().has(t));
297
298 constructor() {
299 const parentForm = inject(NgForm, {optional: true});
300 const parentFormGroup = inject(FormGroupDirective, {optional: true});
301 const defaultErrorStateMatcher = inject(ErrorStateMatcher);
302 const accessor = inject(MAT_INPUT_VALUE_ACCESSOR, {optional: true, self: true});
303 const formField = inject(FORM_FIELD, {optional: true, self: true});
304
305 const element = this._elementRef.nativeElement;
306 const nodeName = element.nodeName.toLowerCase();
307
308 if (accessor) {
309 if (isSignal(accessor.value)) {
310 this._signalBasedValueAccessor = accessor;
311 } else {
312 this._inputValueAccessor = accessor;
313 }
314 } else {
315 // If no input value accessor was explicitly specified, use the element as the input value
316 // accessor.
317 this._inputValueAccessor = element;
318 }
319
320 this._previousNativeValue = this.value;
321
322 // Force setter to be called in case id was not specified.
323 this.id = this.id;
324
325 // On some versions of iOS the caret gets stuck in the wrong place when holding down the delete
326 // key. In order to get around this we need to "jiggle" the caret loose. Since this bug only
327 // exists on iOS, we only bother to install the listener on iOS.
328 if (this._platform.IOS) {
329 this._ngZone.runOutsideAngular(() => {
330 this._cleanupIosKeyup = this._renderer.listen(element, 'keyup', this._iOSKeyupListener);
331 });
332 }
333
334 this._errorStateTracker = new _ErrorStateTracker(
335 defaultErrorStateMatcher,
336 formField || this.ngControl,
337 parentFormGroup,
338 parentForm,
339 this.stateChanges,
340 );
341 this._isServer = !this._platform.isBrowser;
342 this._isNativeSelect = nodeName === 'select';
343 this._isTextarea = nodeName === 'textarea';
344 this._isInFormField = !!this._formField;
345 this.disabledInteractive = this._config?.disabledInteractive || false;
346
347 if (this._isNativeSelect) {
348 this.controlType = (element as HTMLSelectElement).multiple
349 ? 'mat-native-select-multiple'
350 : 'mat-native-select';
351 }
352
353 if (this._signalBasedValueAccessor) {
354 effect(() => {
355 // Read the value so the effect can register the dependency.

Callers

nothing calls this directly

Calls 3

listenMethod · 0.80
valueMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected