Skip to content

Instantly share code, notes, and snippets.

@rajatk16
Created April 11, 2019 23:50
Show Gist options
  • Save rajatk16/ef2fc7a91d77a74bdb1fc2cc6c472c6a to your computer and use it in GitHub Desktop.
Save rajatk16/ef2fc7a91d77a74bdb1fc2cc6c472c6a to your computer and use it in GitHub Desktop.
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