Advertisement
MrMGomes

Untitled

Mar 10th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. HTML:
  2.  
  3. <ion-item>
  4.     <ion-label stacked>Label do campo</ion-label>
  5.     <ion-input type="text" formControlName="nomeCampoNoForm"></ion-input>
  6. </ion-item>
  7. <ion-item *ngIf="!form.controls.nomeCampoNoForm.valid && (form.controls.nomeCampoNoForm.dirty || form.controls.nomeCampoNoForm.touched)" color="danger">
  8.     <div [hidden]="!form.controls.nomeCampoNoForm.errors.required">
  9.         O campo é obrigatório!
  10.     </div>
  11. </ion-item>
  12.  
  13. TS:
  14.  
  15. import { FormBuilder, FormGroup, Validators } from '@angular/forms';
  16.  
  17. export class ExemploPage {
  18.     item: any;
  19.     form: FormGroup;
  20.     constructor(private formBuilder: FormBuilder) {
  21.         this.item = this.navParams.data.item || {};
  22.  
  23.         this.form = this.formBuilder.group({
  24.             nomeCampoNoForm: [this.item.nomeCampoNoForm, Validators.required],
  25.         })
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement