Created
February 8, 2018 16:26
-
-
Save CHBaker/4ff214df526a6b1397dc84f425c95f4f to your computer and use it in GitHub Desktop.
A basic child/dumb component with a form
This file contains hidden or 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, 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