I have incorporated material.angular.io components into my app, particularly autocomplete. I am customizing it to function as a multi-select, but I am encountering an issue with loading initial values:
export class CaseActivityTimeEditComponent implements OnInit {
public clients: Client[];
clientControl: FormControl = new FormControl();
getClients(): void {
this.clientService.getClients(null,null)
.subscribe(data => {
this.clients = data;
});
}
constructor(private clientService: ClientService) { }
ngOnInit(): void {
this.getClients();
this.filteredClients = this.clientControl.valueChanges
.startWith(this.clients) ==> the issue is that this.clients is UNDEFINED
.map(val => val ? this.filterClient(val) : this.clients);
}
}
Essentially, I want to set initial values for this FormControl, but there is a delay in retrieving the initial values using this.getClients()
.
What would be the most effective approach to resolve this?