This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { BrowserModule } from '@angular/platform-browser'; | |
import { NgModule } from '@angular/core'; | |
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; | |
import { AppComponent } from './app.component'; | |
import { ReactiveFormComponent } from './reactive-form/reactive-form.component'; | |
@NgModule({ | |
declarations: [ | |
AppComponent, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
import { FormGroup, FormBuilder, Validators, AbstractControl, FormControl } from '@angular/forms'; | |
@Component({ | |
selector: 'app-reactive-form', | |
templateUrl: './reactive-form.component.html' | |
}) | |
export class ReactiveFormComponent implements OnInit { | |
constructor(private fb: FormBuilder) { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form novalidate [formGroup]="bookForm"> | |
<h1>Reactive Form Example</h1> | |
<div class="group"> | |
<label for="title">Book Title * </label> | |
<input type="text" | |
[class.error]="!bookTitle.valid && bookTitle.touched" | |
[formControl]="bookTitle" | |
id="title" |