gpt4 book ai didi

angular - 在 Angular 6 中动态选择选项

转载 作者:行者123 更新时间:2023-12-04 14:41:09 25 4
gpt4 key购买 nike

如何选择 option在 Angular 6 中动态?页面有很多select s 如图所示:

here

如果它等于 parcela.forma_parcela,我如何动态选择一个选项的值?
parcela.forma_parcela = [0,1,2,3,4,5,6];

<select (change)="setBancoParcela($event.target.value, parcela)" class="input-default" name="forma_pagamento_1" id="forma_pagamento_1">
<option value="0" [selected]="parcela.forma_parcela == this.value">Banco</option>
<option value="1" [selected]="parcela.forma_parcela == this.value">BNDES</option>
<option value="2" [selected]="parcela.forma_parcela == this.value">Boleto</option>
<option value="3" [selected]="parcela.forma_parcela == this.value">Cartão de Crédito</option>
<option value="4" [selected]="parcela.forma_parcela == this.value">Cartão de Débito</option>
<option value="5" [selected]="parcela.forma_parcela == this.value">CH Descontado</option>
<option value="6" [selected]="parcela.forma_parcela == this.value">Cheque</option>
<option value="7" [selected]="parcela.forma_parcela == this.value">DDA</option>
<option value="8" [selected]="parcela.forma_parcela == this.value">Débito Automático</option>
<option value="9" [selected]="parcela.forma_parcela == this.value">Depósito em C/C</option>
</select>

最佳答案

使动态的正确方法是:

<select id="select-type-basic" [(ngModel)]="status">
<option *ngFor="let status_item of status_values">
{{status_item}}
</option>
</select>

值应避免在选项内,因为这将设置“选择字段”的默认值。默认选择应与 [(ngModel)] 绑定(bind),选项应同样声明。
status : any = "Completed";
status_values: any = ["In Progress", "Completed", "Closed"];

关于angular - 在 Angular 6 中动态选择选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53526495/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com