3

I have use below code for bind repeated drop down and select drop down value which are store in database

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

Select drop down value using ngModel is not work

And module_defaultselection have proper value which are available in option in drop down.

3
  • 1
    Hi Rakesh. Can you provide your component's code which is bound to this template? Commented Nov 1, 2017 at 9:44
  • if your myRole.module_role is string then you should use [value] attribute and if it's an object then use [ngValue] attribute with compareWith function. Commented Nov 1, 2017 at 10:17
  • myRole.module_role is string and i try to use [value] using below code but is not working [value]="myRole.module_role" and [value]="{{myRole.module_role}}" Commented Nov 2, 2017 at 6:18

1 Answer 1

3

Use [ngModelOptions]="{standalone: true}" in select drop down refer below code

<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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.