I have a select loaded from an api (which obviously takes time), I also have 3 divs that I show depending on what has been loaded or selected in the select, what happens when I do:
<div class="panel" *ngIf="tipoSeleccionado.CantidadMaxima =='2'">
It gives an error saying that there is no SelectedType since the api has not yet brought the result and it already wants to show the DIV, how do I execute the call to the api before the div is painted? Thank you so much
That's normal and the solution is not to call the API before loading the DOM.
The solution is to validate that
tipoSeleccionado
it is notnull
before accessing your propertyCantidadMaxima
.This is done with optional chaining . That way only the value of
CantidadMaxima
when it'stipoSeleccionado
already initialized will be read.