2017-08-26 44 views
1

我绑定国家的价值和它的名字dropdownList在编辑模式下(当我点击编辑链接其绑定数据初始化)当我点击下拉列表之前,我选择任何值移动到ONSELECT如何防止它,直到我选择我的价值我怎样才能控制dropdownList,直到我选择我的价值

<div class="form-group col-sm-7" [ngClass]="{'has-error':(EmployeeForm.get('Cnt_Name').touched|| 
           EmployeeForm.get('Cnt_Name').dirty) && 
             !EmployeeForm.get('Cnt_Name').valid}"> 
                <select class="form-control" formControlName="Cnt_Name"[(ngModel)]="EmployeeForm.Cnt_Name" (click)="onSelect($event.target.value)"> 
                 <option [ngValue]="EmployeeForm.Cnt_Id">{{EmployeeForm.Cnt_Name}}</option> 
                 <option *ngFor="let cnt of CountryObj" [value]="cnt.Cnt_Id">{{cnt.Cnt_Name}}</option> 
                </select> 
                <span class="help-block" *ngIf="(EmployeeForm.get('Cnt_Name').touched || EmployeeForm.get('Cnt_Name').dirty) && EmployeeForm.get('Cnt_Name').errors"> 
                 <span *ngIf="EmployeeForm.get('Cnt_Name').errors.required"> Please Select Your Country</span> 
                </span> 
               </div> 

这是我的打字稿代码

onSelect(id: number) { 
     return this._cascading.GetStates(id).subscribe(data => { this.StateObj = data }, (error: any) => this.errorMessage = <any>error); 
    } 

回答

1

变化

<select class="form-control" formControlName="Cnt_Name"[(ngModel)]="EmployeeForm.Cnt_Name" (click)="onSelect($event.target.value)"> 
                 <option > 

<select class="form-control" formControlName="Cnt_Name"[(ngModel)]="EmployeeForm.Cnt_Name" (change)="onSelect($event.target.value)"> 
                 <option>