<!DOCTYPE html>
<html>
<head>
<title>Angular 2 Form Model</title>
<script src="https://npmcdn.com/systemjs@0.19.38/dist/system.src.js"></script>
<script src="https://code.angularjs.org/tools/typescript.js"></script>
<script src="system.config.js"></script>
</head>
<body>
<app-root>Loading...</app-root>
<script>
System.import('main.ts');
</script>
</body>
</html>
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
import { AppModule } from './app/app.module'
platformBrowserDynamic().bootstrapModule(AppModule)
var angularVersion = '2.0.0';
System.config({
baseUrl: '/',
paths: {
'unpkg:*': 'https://unpkg.com/*'
}
});
System.config({
transpiler: 'typescript',
typescriptOptions: { emitDecoratorMetadata: true },
meta: {
'*': {
deps: [ 'zone.js', 'reflect-metadata' ]
}
}
});
System.config({
packageConfigPaths: [
"unpkg:@*/*/package.json"
],
map: {
'@angular/core': 'unpkg:@angular/core@'+angularVersion,
'@angular/compiler': 'unpkg:@angular/compiler@'+angularVersion,
'@angular/common': 'unpkg:@angular/common@'+angularVersion,
'@angular/forms': 'unpkg:@angular/forms@'+angularVersion,
'@angular/platform-browser': 'unpkg:@angular/platform-browser@'+angularVersion,
'@angular/platform-browser-dynamic': 'unpkg:@angular/platform-browser-dynamic@'+angularVersion,
'@angular/http': 'unpkg:@angular/http@'+angularVersion,
'rxjs': 'unpkg:rxjs@5.0.0-beta.12',
'zone.js': 'unpkg:zone.js@0.6.23',
'reflect-metadata': 'unpkg:reflect-metadata@0.1.3',
"crypto": "@empty"
},
packages: {
'app': {
defaultExtension: 'ts',
main: './index.ts'
}
}
});
import { NgModule } '@angular/core';
import { FormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component'
@NgModule({
imports: [
BrowserModule,
FormsModule
],
declarations: [
AppComponent
],
bootstrap: [
AppComponent
]
})
export class AppModule {}
import { Component} from '@angular/core';
import { NgForm } from '@angular/forms';
@Component({
selector: 'app-root',
styles: [`
label { display: block }
`],
templateUrl: 'app/app.component.html',
})
export class AppComponent {
formValues: SignupForm;
registerUser(form: NgForm) {
this.formValues = form.value;
}
}
<form
#signupForm="ngForm"
(ngSubmit)="registerUser(signupForm)">
<label>
Username:
<input type="text" name="username" ngModel />
</label>
<label>
Password:
<input type="password" name="password" ngModel />
</label>
<button type="submit">Sign Up</button>
</form>
<pre>{{ formValues | json }}</pre>