Skip to content

Commit 542b4ad

Browse files
committed
New validator in shared, new form validation and updated dependencies.
1 parent 39b0db0 commit 542b4ad

File tree

8 files changed

+50
-24
lines changed

8 files changed

+50
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
![logo](https://jerouw.nl/wp-content/uploads/2017/05/ngfbmd.png "Logo")
77

88
# Angular 4 | Material Design | Firebase - Starter kit
9-
A full stack starter app containing [Angular 4](https://angular.io) (v5.0.0-beta.1/v4.3.2), [Material](https://material.io/) (v2.0.0-beta.8) and [Firebase](https://firebase.google.com/) (v4.2.0).
9+
A full stack starter app containing [Angular 4](https://angular.io) (v5.0.0-beta.2/v4.3.3), [Material](https://material.io/) (v2.0.0-beta.8) and [Firebase](https://firebase.google.com/) (v4.2.0).
1010

1111

1212
### Project is still in progress

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@
2828
"i18n": "ng-xi18n"
2929
},
3030
"dependencies": {
31-
"@angular/animations": "^4.3.2",
31+
"@angular/animations": "^4.3.3",
3232
"@angular/cdk": "^2.0.0-beta.8",
33-
"@angular/common": "^4.3.2",
34-
"@angular/compiler": "^4.3.2",
35-
"@angular/core": "^4.3.2",
36-
"@angular/forms": "^4.3.2",
37-
"@angular/http": "^4.3.2",
33+
"@angular/common": "^4.3.3",
34+
"@angular/compiler": "^4.3.3",
35+
"@angular/core": "^4.3.3",
36+
"@angular/forms": "^4.3.3",
37+
"@angular/http": "^4.3.3",
3838
"@angular/material": "^2.0.0-beta.8",
39-
"@angular/platform-browser": "^4.3.2",
40-
"@angular/platform-browser-dynamic": "^4.3.2",
41-
"@angular/platform-server": "^4.3.2",
42-
"@angular/router": "^4.3.2",
39+
"@angular/platform-browser": "^4.3.3",
40+
"@angular/platform-browser-dynamic": "^4.3.3",
41+
"@angular/platform-server": "^4.3.3",
42+
"@angular/router": "^4.3.3",
4343
"core-js": "^2.4.1",
4444
"firebase": "^4.2.0",
4545
"hammerjs": "^2.0.8",
@@ -50,7 +50,7 @@
5050
},
5151
"devDependencies": {
5252
"@angular/cli": "^1.2.6",
53-
"@angular/compiler-cli": "^4.3.2",
53+
"@angular/compiler-cli": "^4.3.3",
5454
"@types/jasmine": "^2.5.53",
5555
"@types/node": "^8.0.17",
5656
"codelyzer": "^3.1.2",
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
<form class="form" (ngSubmit)="onSubmit(f)" #f="ngForm">
1+
<form class="form" [formGroup]="form" (ngSubmit)="onSubmit(f)" #f="ngForm">
22
<md-card>
33
<h3>Keep in touch!</h3>
44
<md-input-container class="full-width">
5-
<input mdInput placeholder="Your Email" type="email" id="email" name="email" ngModel required>
5+
<input mdInput formControlName="email" placeholder="Your Email" type="email" ngModel required>
66
</md-input-container>
7+
<div *ngIf="!form.controls.email.valid && form.controls.email.dirty">
8+
<p>Please enter a valid email.</p>
9+
</div>
710
<br />
8-
<button md-raised-button class="primary" type="submit" [disabled]="f.invalid">Submit</button>
11+
<button md-raised-button class="primary" type="submit" [disabled]="form.invalid">Submit</button>
912
</md-card>
1013
</form>

src/app/components/email-me/email-me.component.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
import { Component, OnInit } from '@angular/core';
2-
import { NgForm } from '@angular/forms';
2+
import { NgForm, FormBuilder, Validators, FormGroup } from '@angular/forms';
33

4-
import { AlertService, UserService } from '../shared';
4+
import { UserService, EmailValidator } from '../shared';
55

66
@Component({
77
selector: 'app-email-me',
88
templateUrl: './email-me.component.html',
99
styleUrls: ['./email-me.component.scss']
1010
})
1111
export class EmailMeComponent implements OnInit {
12-
constructor(
13-
private alertService: AlertService,
14-
private userService: UserService) {
12+
public form: FormGroup;
1513

16-
}
14+
constructor(private userService: UserService,
15+
public formBuilder: FormBuilder)
16+
{
17+
this.form = formBuilder.group({
18+
email: ['', Validators.compose([Validators.required, EmailValidator.isValid])]
19+
});
20+
}
1721

1822
ngOnInit() {
1923
}

src/app/components/shared/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from './models'
22
export * from './layout';
33
export * from './services';
44
export * from './interfaces';
5+
export * from './validators';

src/app/components/shared/layout/header/header.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ export class HeaderComponent {
4444

4545
public menuItems: Array<Object> = [
4646
{
47-
icon: 'photo_library',
48-
title: 'Portfolio',
49-
link: 'https://jerouw.nl'
47+
icon: 'description',
48+
title: 'Published packages',
49+
link: 'https://www.npmjs.com/~jeroenouw'
5050
},
5151
{
5252
icon: 'link',
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { FormControl } from '@angular/forms';
2+
3+
export class EmailValidator {
4+
5+
static isValid(control: FormControl){
6+
const re = /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/.test(control.value);
7+
8+
if (re){
9+
return null;
10+
}
11+
12+
return {
13+
"invalidEmail": true
14+
};
15+
16+
}
17+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './email';

0 commit comments

Comments
 (0)