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);
}