Hi, I’m very new to Ionic and Angular.
I’m trying to build a form within a new Ionic 3 app that I started yesterday.
I followed this documentation for creating a form using FormBuilder
.
When the form page is loaded, I get this error:
TheFormPage.html:22 ERROR TypeError: Cannot read property 'valid' of undefined
at Object.eval [as updateRenderer] (TheFormPage.html:25)
Here is the entirety of my component source
import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { Validators, FormBuilder, FormGroup } from '@angular/forms';
@Component({
selector: 'page-the-form',
templateUrl: 'the-form.html',
})
export class TheFormPage {
private thing : FormGroup;
constructor(public navCtrl: NavController, private formBuilder: FormBuilder) {
this.thing = this.formBuilder.group({
title: ['', Validators.required],
details: ['', Validators.required],
});
}
logThing(){
console.log(this.thing.value)
}
}
and the template
<ion-header>
<ion-navbar>
<ion-title>Thing!</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<form [formGroup]="thing" (ngSubmit)="logThing()">
<ion-item>
<h1><strong>Make a Thing!</strong></h1>
</ion-item>
<ion-item>
<ion-label stacked>Title</ion-label>
<ion-input type="text" formControlName="title"></ion-input>
</ion-item>
<ion-item>
<ion-label stacked>Details</ion-label>
<ion-textarea formControlName="details"></ion-textarea>
</ion-item>
<button ion-button large type="submit" [disabled]="!todo.valid">
Submit
</button>
</form>
</ion-content>