-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathevent-form.component.ts
108 lines (90 loc) · 3.68 KB
/
event-form.component.ts
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// template for event-form. No functionality added to event services.
import { Component } from '@angular/core';
import { FormGroup, FormControl} from '@angular/forms';
import { EvindService } from './evind.service';
@Component({
selector: 'event-form',
providers: [EvindService],
template: `
<form [formGroup]="form" (ngSubmit)="postEvent()" class="form-horizontal" action="/api/events" method="post">
<fieldset>
<!-- Form Name -->
<legend>Add your own event</legend>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="title">Event Name</label>
<div class="col-md-5">
<input formControlName="title" id="title" name="title" type="text" placeholder="My event" class="form-control input-md">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="eventDate">Event Date</label>
<div class="col-md-5">
<input formControlName="eventDate" id="eventDate" name="eventDate" type="date" placeholder="" class="form-control input-md">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="location">Event Location</label>
<div class="col-md-5">
<input formControlName="location" id="location" name="location" type="text" placeholder="Location" class="form-control input-md">
</div>
</div>
<!-- Textarea -->
<div class="form-group">
<label class="col-md-4 control-label" for="description">Description</label>
<div class="col-md-3">
<textarea formControlName="description" class="form-control" id="description" placeholder="..." name="description"></textarea>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="link">Event Link</label>
<div class="col-md-5">
<input formControlName="link" id="link" name="link" type="text" placeholder="www.event.com" class="form-control input-md">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="imgUrl">Image Link</label>
<div class="col-md-5">
<input formControlName="imgUrl" id="imgUrl" name="imgUrl" type="text" placeholder="www.event.com/picture.jpg" class="form-control input-md">
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="submit"></label>
<div class="col-md-4">
<button id="submit" name="submit" type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</fieldset>
</form>`
})
export class EventFormComponent {
form = new FormGroup({
title: new FormControl(),
location: new FormControl(),
link: new FormControl(),
eventDate: new FormControl(),
description: new FormControl(),
imgUrl: new FormControl(),
});
constructor(private _httpService: EvindService) {
}
postEvent() {
let eventToSend = {
title: this.form.value.title,
location: this.form.value.location,
link: this.form.value.link,
eventDate: this.form.value.eventDate,
description: this.form.value.description,
imgUrl: this.form.value.imgUrl
}
console.log(eventToSend);
this._httpService.postEvent(eventToSend).subscribe((res) => {
console.log('event posted');
})
}
}