2017-02-16 58 views
0

我有[(ngModel)](ngModelChange)属性的下拉列表,但如果我想加载任何默认值使用[value]属性我的ngModel没有给当前更改的值。无法实现双向绑定下拉,这是下JQuery形式

我需要在下拉菜单上进行双向绑定。通常只需要一个选择下拉菜单的工作,当它在我的jQuery窗体中时出现问题。任何人都可以帮忙吗? My.Html:

<select class="form-control" name="state" [(ngModel)]="**myClient.address && myClient.address.state**" (ngModelChange)="getCitiesByState($event)" > 
<option class="form-control" *ngFor="let state of states" [ngValue]='state'>{{state.name}} 
</option> 
</select> 
+2

aaaaaand你的代码是什么? :) – Alex

回答

1

这里是一个下拉势必ngModel设定为 “秒”/ “2” 的默认值:

import { Component } from '@angular/core'; 

@Component({ 
    selector: 'app-native-element-playground', 
    template: ` 
    <select name="option" [(ngModel)]="option"> 
     <option *ngFor="let option of options" [ngValue]="option"> 
      {{ option.name }} 
     </option> 
    </select> 
    {{option | json}} 
    `, 
    styleUrls: ['./native-element-playground.component.css'] 
}) 
export class NativeElementPlaygroundComponent { 
    options = [ 
    { name: 'First', code: '1' }, 
    { name: 'Second', code: '2' }, 
    { name: 'Third', code: '3' } 
    ]; 
    option = this.options[1]; 
} 
+0

谢谢。雅在正常的绑定如预期,但我的下拉内JQuery形式。 –