0
i have a typescript function that receives a json value from my webapi, and I need to pass this result to a select in html...
Service:
teste: teste[];
public getNomes(type: string, formGroup: FormGroup) {
let params: HttpParams = undefined;
params = new HttpParams().set('type', type);
switch (type) {
case "teste":
params = params.set('cod', formGroup.controls['codigoCliente'].value);
this.retornaNomeApi(API + '/Pesquisa/SelectPesquisa', params).subscribe(nome => {this.teste = nome.result});
}
}
HTML:
<select class="form-control" name="pedido">
<option selected>Selecione...</option>
<option *ngFor="let testes of teste">{{testes.cod}} - {{testes.nome}}</option>
</select>
thanks in advance :D
Dude, I tried that way, but it still doesn’t get any feedback
– Bruno Miqueas
Sorry for the obviousness, but there is indeed the return of API data?
– Lucas Brogni
yes, I can see the return of the api in the browser sources
– Bruno Miqueas
Bruno, add in the HTML above the form this code {{ form.value | json }} and see if it shows the request value as empty.
– Lucas Brogni
it shows empty.
– Bruno Miqueas
add this.form.Controls['request']. setValue(this.tests[0], { onlySelf: true }); inside the request subscribe. Theoretically it has to set the 0 position of your array as the default of your select
– Lucas Brogni