-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbook-online.component_copy.ts
121 lines (111 loc) · 3.28 KB
/
book-online.component_copy.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
109
110
111
112
113
114
115
116
117
118
119
120
121
import {
Component,
ViewChild,
ElementRef,
NgZone,
OnInit
} from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import * as moment from 'moment';
import { MapsAPILoader } from '@agm/core';
@Component({
selector: 'app-book-online',
templateUrl: './book-online.component.html',
styleUrls: ['./book-online.component.css']
})
export class BookOnlineComponent implements OnInit {
constructor(private mapsAPILoader: MapsAPILoader, private ngZone: NgZone) {}
@ViewChild('pickupLoc', { static: false }) pickupLoc: ElementRef;
@ViewChild('dropLoc', { static: false }) dropLoc: ElementRef;
minDate = moment().format();
maxDate = moment(this.minDate)
.add(7, 'days')
.format();
autocomplete1: google.maps.places.Autocomplete;
autocomplete2: google.maps.places.Autocomplete;
place1: google.maps.places.PlaceResult;
place2: google.maps.places.PlaceResult;
scheduleCabForm = new FormGroup({
name: new FormControl('', {
validators: [Validators.required, Validators.minLength(4)]
}),
mobile: new FormControl('', {
validators: [
Validators.required,
Validators.pattern(/^[2-9]\d{2}[2-9]\d{2}\d{4}$/)
]
}),
email: new FormControl('', {
validators: [Validators.required, Validators.email]
}),
pickup_date: new FormControl(this.minDate),
pickup_time: new FormControl('14:00'),
passengers: new FormControl(1),
pickup_loc: new FormControl('', {
validators: [Validators.required]
}),
drop_loc: new FormControl('', {
validators: [Validators.required]
})
});
ngOnInit() {
// www.freakyjolly.com/angular-7-6-add-google-maps-in-angular-2-plus-applications-using-angular-google-maps-module-agm-core-easily/
this.mapsAPILoader.load().then(() => {
this.autocomplete1 = new google.maps.places.Autocomplete(
this.pickupLoc.nativeElement,
{
componentRestrictions: { country: 'US' },
types: ['address']
}
);
this.autocomplete2 = new google.maps.places.Autocomplete(
this.dropLoc.nativeElement,
{
componentRestrictions: { country: 'US' },
types: ['address']
}
);
this.autocomplete1.addListener('place_changed', () => {
this.ngZone.run(() => {
this.place1 = this.autocomplete1.getPlace();
console.log(this.place1);
// verify result
if (
this.place1.geometry === undefined ||
this.place1.geometry === null
) {
return;
}
});
});
this.autocomplete2.addListener('place_changed', () => {
this.ngZone.run(() => {
this.place2 = this.autocomplete2.getPlace();
console.log(this.place2);
if (
this.place2.geometry === undefined ||
this.place2.geometry === null
) {
return;
}
});
});
});
}
setPickupLoc() {
this.scheduleCabForm.setValue({
pickup_loc: this.place1.formatted_address
});
}
setDropLoc() {
this.scheduleCabForm.setValue({
drop_loc: this.place2.formatted_address
});
}
onSubmit() {
console.log('was submitted!');
}
onBlur() {
console.log(this.scheduleCabForm.get('email'));
}
}