import { Component } from '@angular/core';
import { FormBuilder, Validators } from '@angular/forms';
@Component({
selector: 'my-component',
template: `
`
})
export class MyComponent {
myForm = this.fb.group({
name: ['', Validators.required]
});
constructor(private fb: FormBuilder) {}
}
import { Component } from '@angular/core';
import { FormBuilder, Validators } from '@angular/forms';
@Component({
selector: 'my-component',
template: `
Form value: {{ myForm.value | json }}
`
})
export class MyComponent {
myForm = this.fb.group({
name: ['', Validators.required]
});
constructor(private fb: FormBuilder) {}
submit() {
console.log(this.myForm.value.name);
}
}