2016-08-26 67 views
2

如何爲選擇標籤寫入驗證? 這是我選擇標記的代碼,但我沒有得到select的驗證,消息也沒有出現。在頁面上選擇元素的驗證

HTML代碼

<form> 
<ion-list [ngFormModel]="registrationForm"> 
<ion-item> 
     <ion-label floating>Preffer Payment<span class="redtxt">*</span></ion-label> 
     <ion-select ngControl="pay"> 
      <ion-option>Neft/Rtgs/Imps</ion-option> 
      <ion-option>Debet/Credit</ion-option> 
      <ion-option>Net Banking</ion-option> 
     </ion-select> 
     <div control="pay" class="validation-error">This is required</div> 
    </ion-item> 
</ion-list> 
<form> 

TS碼

public registrationForm:any; 
constructor(public navCtrl: NavController,public _form: FormBuilder) { 
this.registrationForm = this._form.group({ 
      "pay":["",Validators.required] 
     }) 
    } 

回答

0

可以使用controls陣列的你registrationForm顯示一條消息,如果該屬性是無效的。

<form> 
    <ion-list [ngFormModel]="registrationForm"> 

    <ion-item> 
     <ion-label floating>Preffer Payment<span class="redtxt">*</span></ion-label> 
     <ion-select ngControl="pay"> 
      <ion-option>Neft/Rtgs/Imps</ion-option> 
      <ion-option>Debet/Credit</ion-option> 
      <ion-option>Net Banking</ion-option> 
     </ion-select>  
    </ion-item> 

    <!-- Error message --> 
    <ion-item *ngIf="!registrationForm.controls.pay.valid"> 
     <div control="pay" class="validation-error">This is required</div> 
    </ion-item> 

    </ion-list> 
<form> 
相關問題