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

Function ngOnInit

src/material/datepicker/date-range-input-parts.ts:98–116  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

96 }
97
98 ngOnInit() {
99 // We need the date input to provide itself as a `ControlValueAccessor` and a `Validator`, while
100 // injecting its `NgControl` so that the error state is handled correctly. This introduces a
101 // circular dependency, because both `ControlValueAccessor` and `Validator` depend on the input
102 // itself. Usually we can work around it for the CVA, but there's no API to do it for the
103 // validator. We work around it here by injecting the `NgControl` in `ngOnInit`, after
104 // everything has been resolved.
105 const ngControl = this._injector.get(NgControl, null, {optional: true, self: true});
106
107 this._errorStateTracker.formField = this._injector.get(FORM_FIELD, null, {
108 optional: true,
109 self: true,
110 });
111
112 if (ngControl) {
113 this.ngControl = ngControl;
114 this._errorStateTracker.ngControl = ngControl;
115 }
116 }
117
118 ngAfterContentInit(): void {
119 this._register();

Callers

nothing calls this directly

Calls 1

getMethod · 0.65

Tested by

no test coverage detected