Created
April 11, 2019 23:50
-
-
Save rajatk16/ef2fc7a91d77a74bdb1fc2cc6c472c6a to your computer and use it in GitHub Desktop.
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, Input, Output, EventEmitter} from '@angular/core'; | |
import { FormGroup, FormControl } from '@angular/forms'; | |
@Component({ | |
selector: 'hero-form', | |
templateUrl: './hero-form.component.html', | |
styleUrls: ['./hero-form.component.css'] | |
}) | |
export class HeroFormComponent implements OnInit { | |
heroForm: FormGroup; | |
@Input() | |
title; | |
@Input() | |
realname; | |
@Input() | |
occupation; | |
@Input() | |
location; | |
@Input() | |
firstappearance; | |
@Output() | |
heroSubmit = new EventEmitter(); | |
constructor() {} | |
ngOnInit() { | |
this.heroForm = new FormGroup({ | |
title: new FormControl(this.title), | |
realname: new FormControl(this.realname); | |
occupation: new FormControl(this.occupation); | |
location: new FormControl(this.location); | |
firstappearance: new FormControl(this.firstappearance); | |
}); | |
} | |
onSubmit({ value, valid }) { | |
if (valid) { | |
this.heroSubmit.next(value); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment