-
Notifications
You must be signed in to change notification settings - Fork 1
/
TypeScript
36 lines (30 loc) · 914 Bytes
/
TypeScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
@Component({
selector: 'app-comment-create',
templateUrl: './comment-create.component.html',
styleUrls: ['./comment-create.component.css']
})
export class CommentCreateComponent implements OnInit {
form: FormGroup;
constructor(private fb: FormBuilder) { }
ngOnInit() {
this.form = this.fb.group({
text: ['', [Validators.required]]
});
}
createComment() {
const comment = {
text: this.form.get('text').value
};
// відправка постового запиту
fetch('http://jsonplaceholder.typicode.com/comments', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(comment)
})
.then(response => response.json())
.then(comment => {
console.log(comment