HTML- I'm trying to use Mat-autocomplete but its not working on very first time when component gets loaded i.e in ngOnInit(), Its saying cannot read properties of null (reading 'map')
<mat-form-field appearance="outline">
<input type="text" placeholder="Pick one" aria-label="Number" matInput [formControl]="myControl" [(ngModel)]="element.NEW_AMENITY_NAME" [matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete" class="assignedSeat-select" (optionSelected)='onSelect($event.option, i)'>
<mat-option *ngFor="let item of filteredOptions | async" [value]="item">
{{item}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
TS file -
ngOnInit(): void {
this.infoService.AmenityList.subscribe((res)=>{
this.AmenityList = res;
this.assignForm.push(this.createForm(1))
this.dataSource = [...this.assignForm.controls];
console.log(this.dataSource.END_TIME , "data");
})
this.displayName = this.AmenityList.map(a=>a.DISPLAY_NAME);
this.filteredOptions = this.myControl.valueChanges.pipe(
startWith(''),
map(value => this._filter(value || '')),
);
}
its not working on very first time when we are laoding the component, attached image of error-