-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontact.component.ts
More file actions
52 lines (42 loc) · 1.58 KB
/
contact.component.ts
File metadata and controls
52 lines (42 loc) · 1.58 KB
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
import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroupDirective, NgForm, Validators, FormBuilder, FormGroup } from '@angular/forms';
import { ErrorStateMatcher } from '@angular/material/core';
import { Contact } from './shared/contact';
/** Error when invalid control is dirty, touched, or submitted. */
export class MyErrorStateMatcher implements ErrorStateMatcher {
isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean {
const isSubmitted = form && form.submitted;
return !!(control && control.invalid && (control.dirty || control.touched || isSubmitted));
}
}
@Component({
selector: 'app-contact',
templateUrl: './contact.component.html',
styleUrls: ['./contact.component.css']
})
export class ContactComponent implements OnInit {
model: Contact = new Contact('', '', '', '');
formContact: FormGroup;
emailFormControl = new FormControl('', [
Validators.required,
Validators.email,
]);
matcher = new MyErrorStateMatcher();
constructor(private _formbuilder: FormBuilder) {
this.formContact = _formbuilder.group({
'name': new FormControl(this.model.name, [
Validators.required,
]),
'email': new FormControl(this.model.email, [Validators.required, Validators.email]),
'subject': new FormControl(this.model.subject, [Validators.required]),
'message': new FormControl(this.model.message, [Validators.required]),
});
}
// private _builderForm(){
// }
ngOnInit() {
}
OnSubmit(form: Contact){
console.log('you submitted value:', form);
}
}