Angular 2+选择框值未更新问题

时间:2018-07-27 10:29:33

标签: angular

加载全部(3个列表)选择框列表后,它更新了ui,但是每个选择框上的值均未更新,为什么? enter image description here

 <div class="form-group row">
                                <label for="cat_mid" class="col-sm-3 col-form-label">Top cat</label>
                                <div class="col-sm-9">
                                    <select (change)="onChangeTop_()" [(ngModel)]="top_select_val" class="form-control" name="t1">
                                        <option *ngFor="let c22 of topcat_select" [ngValue]="c22"  [attr.value]="c22">{{c22 }}</option>
                                      </select>
                                </div>
                            </div>

                            <div class="form-group row">
                                <label for="cat_mid" class="col-sm-3 col-form-label">Mid cat</label>
                                <div class="col-sm-9">
                                    <select (change)="onChangeMid_()" [(ngModel)]="mid_select_val" class="form-control" name="m1">
                                        <option *ngFor="let c21 of midcat_select" [ngValue]="c21" [attr.value]="c21">{{c21 }}</option>
                                      </select>
                                </div>
                            </div>

                            <div class="form-group row">
                                <label for="cat_mid" class="col-sm-3 col-form-label">Leaf cat</label>
                                <div class="col-sm-9">
                                    <select [(ngModel)]="leaf_select_val" class="form-control" name="l1">
                                    <option    *ngFor="let cm3 of leafcat_select" [ngValue]="cm3" [attr.value]="cm3"  >{{cm3}}</option>
                                  </select>
                                </div>

                            </div>

当我尝试检查mid_select_val中的值时,该值为空或未定义。
现在如何获得价值?
如果用户更改任何值,则表示正在更新
当我们更新列表时,它不是在调用此函数(change)=“ onChangeMid_()”,这是怎么解决的?

1 个答案:

答案 0 :(得分:0)

  

在您的选择框中删除[ngValue]="c21" [attr.value]="c21">

或尝试

  

[ngValue]="top_select_val = c21" [attr.value]=" top_select_val =c21">