Good afternoon, I am creating an angular 14 form and I need it to select but its options are filled with data that comes from a database query and it comes in this way
[
{
"nombre": "devNoob",
"value": 10
},
{
"nombre": "devNoob2",
"value": 11
}
]
and in this way I have to fill my select, this was what I did at first
datosSelect: Object;
llenarDatosSelect():void {
const datosArr: Array<Object> = respuesta /*respuesta serian los datos de la DB*/
datos.push(obj => {
this.datosSelect = obj;
})
}
but in the HTML I don't know what to put for this to work try to do this
<select>
<option value="{{datosSelect.value}}">{{datosSelect.nombre}}</option>
<option value="{{datosSelect.value}}">{{datosSelect.nombre}}</option>
<option value="{{datosSelect.value}}">{{datosSelect.nombre}}</option>
<option value="{{datosSelect.value}}">{{datosSelect.nombre}}</option>
</select>
but let's see... first I don't know how much data will come this may vary apart I don't know why I thought this was going to work hahahaha: V, thanks for your help.
Good afternoon @devNoob to do this you need to do a repetitive loop, angular has a solution for this and it's the *ngFor good first of all you don't need to access the Array or your array and extract the objects, so the code would look like this
in the HTML you would just do this, it is not necessary to do an option for each object
and ready when executing the function this will create the options that are necessary, I hope I have helped you: D. For more information consult the documentation of the *ngFor of angular