I have a list checkbox and a text area in my page, well how to work with FormBuilder, Group and Validarors and how to get the values of checkbox ?
modalPage.ts
<form [formGroup]="dump" (ngSubmit)="createWaste()">
<ion-item *ngFor="let waste of typeWaste">
<ion-label>{{ waste.name }}</ion-label>
<ion-checkbox color="dark" formControlName="waste" checked="true"></ion-checkbox>
</ion-item>
...
<textarea #myInput id="myInput" rows="1" maxLength="500" (keyup)="resize()" formControlName="description" placeholder="Digite o seu texto aqui"></textarea>
...
<button type="submit" ion-button block [disabled]="!dump.valid">Despejar</button>
</form>
In my component I have the following code
constructor(public viewCtrl: ViewController, private formB: FormBuilder, private service: EvictionsProvider) {
this.getWaste();
this.getForm();
}
getWaste() {
this.typeWaste = [
{ id: 1, name: 'Vidro', selected: true },
{ id: 2, name: 'Papel', selected: true },
{ id: 3, name: 'Ferro', selected: true },
{ id: 4, name: 'Vidro', selected: true },
{ id: 5, name: 'Vidro', selected: true },
{ id: 6, name: 'Vidro', selected: true },
]
}
here I get the data of form
getForm() {
this.dump = this.formB.group({
waste: ['', Validators.required],
description: [''],
});
}
createWaste() {
.....
}