Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
angular 4中的动态绑定下拉选项_Angular_Angular4 Forms - Fatal编程技术网

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}”