Skip to content

Instantly share code, notes, and snippets.

@CHBaker
Created February 8, 2018 16:26
Show Gist options
  • Save CHBaker/4ff214df526a6b1397dc84f425c95f4f to your computer and use it in GitHub Desktop.
Save CHBaker/4ff214df526a6b1397dc84f425c95f4f to your computer and use it in GitHub Desktop.
A basic child/dumb component with a form
import { Component, Input } from '@angular/core';
import { FormGroup } from '@angular/forms';
@Component({
selector: 'app-child',
template: `
<h1>Enter your name</h1>
<form
[formGroup]="nameForm"
(ngSubmit)="submitForm(nameForm)"
>
<input
type="text"
formControlName="firstName"
placeholder="first"
>
<input
type="text"
formControlName="lastName"
placeholder="last"
>
<button type="submit">launch to space</button>
</form>
`,
styleUrls: ['./child.component.css']
})
export class ChildComponent {
@Input() nameForm: FormGroup;
submitForm(form: FormGroup) {
console.log(form);
// really you would be using an event emitter
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment