Skip to content

Instantly share code, notes, and snippets.

@duarte171183
Created September 27, 2019 06:36
Show Gist options
  • Save duarte171183/70f2e5d5ff91a7a4b697dc29a7eb06b6 to your computer and use it in GitHub Desktop.
Save duarte171183/70f2e5d5ff91a7a4b697dc29a7eb06b6 to your computer and use it in GitHub Desktop.
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms';
import { ArticleService } from 'src/app/services/article.service';
import { Article } from 'src/app/model/article';
@Component({
selector: 'app-articles-form',
templateUrl: './articles-form.component.html',
styleUrls: ['./articles-form.component.css']
})
export class ArticlesFormComponent implements OnInit {
constructor(private articleService: ArticleService) { }
articleForm:FormGroup;
ngOnInit() {
this.articleForm = new FormGroup({
title: new FormControl(''),
body: new FormControl(''),
});
}
onSubmit(){
this.articleService.create_article(this.articleForm.value)
.subscribe(data => console.log(data), error => console.log(error));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment