angular 4中的动态绑定下拉选项
我使用下面的代码绑定重复下拉列表并选择存储在数据库中的下拉值angular 4中的动态绑定下拉选项,angular,angular4-forms,Angular,Angular4 Forms,我使用下面的代码绑定重复下拉列表并选择存储在数据库中的下拉值 <div class="form-group row" *ngFor="let option of roles let x = index"> <div class="col-8"> <select [disabled]="adminstratorStatus=='true'" class="form-control custom-select col-12" id="compan
<div class="form-group row" *ngFor="let option of roles let x = index">
<div class="col-8">
<select [disabled]="adminstratorStatus=='true'" class="form-control custom-select col-12" id="company_info_management" required
[(ngModel)]="option.module_defaultselection" name="company_info_management"
#company_info_management="ngModel" (ngModelChange)="onSelect($event,x)">
<option value=''>--select company--</option>
<option *ngFor="let myRole of option.module_role;" value= {{myRole.module_role}}>
<!--[ngValue]="myRole.module_role"-->
{{myRole.module_role_description | translate }}
</option>
</select>
</div>
</div>
--精选公司--
{{myRole.module_role_description | translate}}
使用ngModel选择下拉列表值无效
和模块_defaultselection具有适当的值,这些值在下拉列表中的选项中可用。在选择下拉列表中使用[ngModelOptions]=“{standalone:true}”,请参阅下面的代码
<div class="form-group row" *ngFor="let option of roles let x = index">
<div class="col-8">
<select [disabled]="adminstratorStatus=='true'" class="form-control custom-select col-12" id="company_info_management" required
[(ngModel)]="roles[x].module_defaultselection" name="company_info_management"
#company_info_management="ngModel" [ngModelOptions]="{standalone: true}">
<option value="">--select company--</option>
<option *ngFor="let myRole of option.module_role;" value="{{myRole.module_role}}"> {{myRole.module_role_description | translate }} </option>
</select>
</div>
</div>
--精选公司--
{{myRole.module_role_description | translate}}
Hi Rakesh。你能提供绑定到此模板的组件代码吗?如果你的myRole.module\u role
是字符串,那么你应该使用[value]
属性,如果它是一个对象,那么使用[ngValue]
属性与compareWith
函数进行比较。myRole.module\u角色是字符串,我尝试使用[value]正在使用下面的代码但不起作用[value]=“myRole.module_role”和[value]=“{{myRole.module_role}”