<!DOCTYPE html>
<html>
<head>
<title>Angular Material Plunker</title>
<!-- Load common libraries -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/typescript/2.1.6/typescript.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/2.4.1/core.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/zone.js/0.7.2/zone.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.47/system.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/web-animations/2.2.2/web-animations.min.js"></script>
<!-- Configure SystemJS -->
<script src="systemjs.config.js"></script>
<script>
System
.import('main.ts')
.catch(console.error.bind(console));
</script>
<!-- Load the Angular Material stylesheet -->
<link href="https://rawgit.com/angular/material2-builds/master/prebuilt-themes/indigo-pink.css" rel="stylesheet">
<style>body { font-family: Roboto, Arial, sans-serif; margin: 0 }</style>
</head>
<body class="mat-app-background">
<material-app>Loading the Angular Material App...</material-app>
</body>
</html>
<!--
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
-->
import { Component, OnInit, Input } from '@angular/core';
import { User } from './user';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
@Component({
selector: 'material-app',
templateUrl: 'app.component.html'
})
export class AppComponent {
@Input() user: User;
users: User[];
token: string;
submitted = false;
active = true;
userForm: FormGroup;
constructor(private fb: FormBuilder) {
this.buildForm();
}
ngOnInit() {
this.buildForm();
}
ngOnChanges() {
this.userForm.reset({
inputEmail: this.user.email,
inputFirstName: this.user.firstName,
inputLastName: this.user.lastName,
// inputAddress: this.user.address,
// inputCity: this.user.city,
// inputState: this.user.state,
// inputPostalcode: this.user.postalcode,
// inputCountry: this.user.country,
// inputContactNumber: this.user.contactNumber
});
}
buildForm(): void {
this.userForm = this.fb.group({
'inputEmail': ['', [
Validators.email,
Validators.required
]],
'inputFirstName': ['', [
Validators.required,
Validators.minLength(2),
Validators.maxLength(30)
]],
'inputLastName': ['', [
Validators.required,
Validators.minLength(2),
Validators.maxLength(30)
]],
// 'inputAddress': ['',
// Validators.required
// ],
// 'inputCity': ['',
// Validators.required
// ],
// 'inputState': ['',
// Validators.required
// ],
// 'inputPostalcode': ['',
// Validators.required
// ],
// 'inputCountry': ['',
// Validators.required
// ],
// 'inputContactNumber': ['',
// Validators.required
// ]
});
this.userForm.valueChanges
.subscribe(data => this.onValueChanged(data));
this.onValueChanged(); // (re)set validation messages now
}
onValueChanged(data?: any) {
if (!this.userForm) { return; }
const form = this.userForm;
for (const field in this.formErrors) {
// clear previous error message (if any)
this.formErrors[field] = '';
const control = form.get(field);
if (control && control.dirty && !control.valid) {
const messages = this.validationMessages[field];
for (const key in control.errors) {
this.formErrors[field] += messages[key] + ' ';
}
}
}
}
formErrors = {
'inputEmail': '',
'inputFirstName': '',
'inputLastName': '',
// 'inputAddress': '',
// 'inputCity': '',
// 'inputState': '',
// 'inputPostalcode': '',
// 'inputCountry': '',
// 'inputContactNumber': ''
};
validationMessages = {
'inputEmail': {
'required': 'Email is required.',
'email': 'Email not valid.'
},
'inputFirstName': {
'required': 'First name is required.',
'minlength': 'First name must be at least 2 characters long.',
'maxlength': 'First name cannot be more than 30 characters long.'
},
'inputLastName': {
'required': 'Last name is required.',
'minlength': 'Last name must be at least 2 characters long.',
'maxlength': 'Last name cannot be more than 30 characters long.'
},
// 'inputAddress': {
// 'required': 'Address is required.'
// },
// 'inputCity': {
// 'required': 'City is required.'
// },
// 'inputState': {
// 'required': 'State is required.'
// },
// 'inputPostalcode': {
// 'required': 'Postcode is required.'
// },
// 'inputCountry': {
// 'required': 'Country is required.'
// },
// 'inputContactNumber': {
// 'required': 'Contact number is required.'
// }
};
}
/*
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/
<div class="container" id="userContainer">
<div class="row">
<h1>User Management</h1>
</div>
<br>
<form id="formCreateUser" (ngSubmit)="onSubmit()" *ngIf="active" [formGroup]="userForm">
<md-input-container>
<input mdInput name="inputFirstName" placeholder="First name" formControlName="inputFirstName>
<md-error *ngIf=" formErrors.inputFirstName ">
{{ formErrors.inputFirstName }}
</md-error>
</md-input-container>
</form>
</div>
/** Add Transpiler for Typescript */
System.config({
transpiler: 'typescript',
typescriptOptions: {
emitDecoratorMetadata: true
},
packages: {
'.': {
defaultExtension: 'ts'
},
'vendor': {
defaultExtension: 'js'
}
}
});
System.config({
map: {
'main': 'main.js',
// Angular specific mappings.
'@angular/core': 'https://unpkg.com/@angular/core/bundles/core.umd.js',
'@angular/common': 'https://unpkg.com/@angular/common/bundles/common.umd.js',
'@angular/compiler': 'https://unpkg.com/@angular/compiler/bundles/compiler.umd.js',
'@angular/animations': "https://unpkg.com/@angular/animations/bundles/animations.umd.js",
'@angular/animations/browser': 'https://unpkg.com/@angular/animations/bundles/animations-browser.umd.js',
'@angular/http': 'https://unpkg.com/@angular/http/bundles/http.umd.js',
'@angular/forms': 'https://unpkg.com/@angular/forms/bundles/forms.umd.js',
'@angular/router': 'https://unpkg.com/@angular/router/bundles/router.umd.js',
'@angular/platform-browser': 'https://unpkg.com/@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser/animations': 'https://unpkg.com/@angular/platform-browser/bundles/platform-browser-animations.umd.js',
'@angular/platform-browser-dynamic': 'https://unpkg.com/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/material': 'https://rawgit.com/angular/material2-builds/master/bundles/material.umd.js',
'@angular/cdk': 'https://rawgit.com/angular/cdk-builds/master/bundles/cdk.umd.js',
// Third party libraries
'tslib': 'https://unpkg.com/tslib@1.7.1',
'rxjs': 'https://unpkg.com/rxjs',
},
packages: {
// Thirdparty barrels.
'rxjs': { main: 'index' },
}
});
/*
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {BrowserModule} from '@angular/platform-browser';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {HttpModule} from '@angular/http';
import {AppComponent} from './app.component';
import {CdkTableModule} from '@angular/cdk'
import {
MdAutocompleteModule,
MdButtonModule,
MdButtonToggleModule,
MdCardModule,
MdCheckboxModule,
MdChipsModule,
MdCoreModule,
MdDatepickerModule,
MdDialogModule,
MdExpansionModule,
MdGridListModule,
MdIconModule,
MdInputModule,
MdListModule,
MdMenuModule,
MdNativeDateModule,
MdProgressBarModule,
MdProgressSpinnerModule,
MdRadioModule,
MdRippleModule,
MdSelectModule,
MdSidenavModule,
MdSliderModule,
MdSlideToggleModule,
MdSnackBarModule,
MdTabsModule,
MdToolbarModule,
MdTooltipModule,
OverlayModule
} from '@angular/material';
/**
* NgModule that includes all Material modules that are required to serve
* the Plunker.
*/
@NgModule({
exports: [
// CDk
CdkTableModule,
// Material
MdAutocompleteModule,
MdButtonModule,
MdButtonToggleModule,
MdCardModule,
MdCheckboxModule,
MdChipsModule,
MdDatepickerModule,
MdDialogModule,
MdExpansionModule,
MdGridListModule,
MdIconModule,
MdInputModule,
MdListModule,
MdMenuModule,
MdCoreModule,
MdProgressBarModule,
MdProgressSpinnerModule,
MdRadioModule,
MdRippleModule,
MdSelectModule,
MdSidenavModule,
MdSlideToggleModule,
MdSliderModule,
MdSnackBarModule,
MdTabsModule,
MdToolbarModule,
MdTooltipModule,
MdNativeDateModule,
// Material (future CDK)
OverlayModule,
]
})
export class PlunkerMaterialModule {}
@NgModule({
imports: [
BrowserModule,
CommonModule,
HttpModule,
PlunkerMaterialModule,
BrowserAnimationsModule
],
declarations: [AppComponent],
bootstrap: [AppComponent],
providers: []
})
export class PlunkerAppModule {}
platformBrowserDynamic().bootstrapModule(PlunkerAppModule);
/*
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/
export class User {
constructor(
public type: string,
public firstName: string,
public lastName: string,
public email: string,
// public accNum: string,
// public bsb: string,
// public bankName: string,
// public branchName: string,
// public accName: string,
public address: string,
public city: string,
public state: string,
public postalcode: string,
public country: string,
public contactNumber: string,
public secondContactNumber: string
){}
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ReactiveFormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { UserService } from './user.service';
import { HttpModule, JsonpModule } from '@angular/http';
import { MaterialModule } from '@angular/material';
// import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
// import {MdButtonModule, MdCheckboxModule} from '@angular/material';
import { FormUserComponentComponent } from './form-user-component/form-user-component.component';
import { MenuFormComponent } from './menu-form/menu-form.component';
@NgModule({
imports: [ BrowserModule, ReactiveFormsModule, HttpModule, JsonpModule,
MaterialModule,
// BrowserAnimationsModule,
// MdButtonModule, MdCheckboxModule
],
declarations: [ AppComponent, FormUserComponentComponent, MenuFormComponent ],
bootstrap: [ AppComponent ],
providers: [ UserService ]
})
export class AppModule { }