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

Method ngOnInit

src/material/list/list-option.ts:174–195  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

172 private _inputsInitialized = false;
173
174 ngOnInit() {
175 const list = this._selectionList;
176
177 if (list._value && list._value.some(value => list.compareWith(this._value, value))) {
178 this._setSelected(true);
179 }
180
181 const wasSelected = this._selected;
182
183 // List options that are selected at initialization can't be reported properly to the form
184 // control. This is because it takes some time until the selection-list knows about all
185 // available options. Also it can happen that the ControlValueAccessor has an initial value
186 // that should be used instead. Deferring the value change report to the next tick ensures
187 // that the form control value is not being overwritten.
188 Promise.resolve().then(() => {
189 if (this._selected || wasSelected) {
190 this.selected = true;
191 this._changeDetectorRef.markForCheck();
192 }
193 });
194 this._inputsInitialized = true;
195 }
196
197 override ngOnDestroy(): void {
198 super.ngOnDestroy();

Callers

nothing calls this directly

Calls 4

_setSelectedMethod · 0.95
resolveMethod · 0.80
markForCheckMethod · 0.80
compareWithMethod · 0.45

Tested by

no test coverage detected