I have an angular application that makes a server call on ngOnInit()
and returns a result. I then use the result to populate a model in my template. My template is loading before the call is finished, giving me an undefined error. How can I ensure the call has completed before the template loads?
<code>ngOnInit(): void {
this.GetCurrentSelectedProducts();
}
GetCurrentSelectedProducts() {
this.proposalService.getCurrentSelectedProducts(this.proposalId).subscribe(response => {
this.productResponse = response.result;
});
}
</code>
<code>ngOnInit(): void {
this.GetCurrentSelectedProducts();
}
GetCurrentSelectedProducts() {
this.proposalService.getCurrentSelectedProducts(this.proposalId).subscribe(response => {
this.productResponse = response.result;
});
}
</code>
ngOnInit(): void {
this.GetCurrentSelectedProducts();
}
GetCurrentSelectedProducts() {
this.proposalService.getCurrentSelectedProducts(this.proposalId).subscribe(response => {
this.productResponse = response.result;
});
}
..
<code><select [(ngModel)]="productResponse.Id">
</code>
<code><select [(ngModel)]="productResponse.Id">
</code>
<select [(ngModel)]="productResponse.Id">