2
I’m trying to generate a dynamic page with Angular 9, my idea is every key in the dictionary create an optgoup tag and each value an option, but I’m not able to access the values of the Dict object.
Code:
<optgroup *ngFor="let categoria in categorias" [label]="categoria">
<option *ngFor="let valor in categorias[categoria]" >{{ valor }}</option>
</optgroup>
Example:
// Dict
var categorias = {
"Pediatra": ["Igor", "Luiz", "Ricardo"],
"Ortopedista ": ["João", "Lucas", "Julia"]
};
Upshot:
<optgroup label="Pediatra">
<option>Igor</option>
<option>Luiz</option>
<option>Ricardo</option>
</optgroup>
<optgroup label="Ortopedista">
<option>João</option>
<option>Lucas</option>
<option>Julia</option>
</optgroup>
Does an error occur or just doesn’t go out as expected?
– mbissonho
No error occurred, Angular generated the build and showed the empty optgroup tag. But the Geeksilva response worked well.
– Igor Gabriel