Skip to content

Instantly share code, notes, and snippets.

@johnrsimoneau
johnrsimoneau / reactive-form.component.html
Last active May 11, 2018 13:45
Template for the reactive form
<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"
@johnrsimoneau
johnrsimoneau / reactive-form.component.ts
Last active May 3, 2018 18:11
Building the reactive-form.component.ts
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) { }
@johnrsimoneau
johnrsimoneau / app.module.ts
Last active May 3, 2018 18:10
Importing Angular's forms into the app.module.ts file.
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,