Created
June 24, 2015 06:02
-
-
Save michaelbromley/48947220f7a115a0486f to your computer and use it in GitHub Desktop.
Angular 2 Demo Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="typings/angular2/angular2.d.ts" /> | |
import {Component, Directive, View, Inject, coreDirectives, bootstrap} from 'angular2/angular2'; | |
import {NameService} from 'nameService'; | |
import {Logger} from 'logger'; | |
@Component({ | |
selector: 'my-app' | |
}) | |
@View({ | |
template: ` | |
<div> | |
<input type="text" #input (keyup)="update(input.value)" logger> | |
<div *ng-for="#name of names"> | |
<name-component name="name">Hello {{ name }}</name-component> | |
</div> | |
</div> | |
`, | |
directives: [coreDirectives, Logger] | |
}) | |
class MyAppComponent { | |
private names; | |
constructor(@Inject(NameService) nameService) { | |
this.names = [nameService.getName()]; | |
} | |
update(val: string) { | |
this.names = val.split(','); | |
} | |
} | |
bootstrap(MyAppComponent, [NameService]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Angular 2 Demo</title> | |
<script src="https://github.jspm.io/jmcriffey/[email protected]/traceur-runtime.js"></script> | |
<script src="https://jspm.io/[email protected]"></script> | |
<script src="https://code.angularjs.org/2.0.0-alpha.26/angular2.dev.js"></script> | |
</head> | |
<body> | |
<!-- The app component created in app.ts --> | |
<my-app></my-app> | |
<script>System.import('app');</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="typings/angular2/angular2.d.ts" /> | |
import {Directive} from 'angular2/angular2'; | |
@Directive({ | |
selector: '[logger]', | |
hostListeners: { | |
'change': 'logValue($event)' | |
} | |
}) | |
export class Logger { | |
constructor() { | |
console.log('logger instantiated!'); | |
} | |
logValue(event: Event) { | |
var target: HTMLInputElement = <HTMLInputElement>event.target; | |
console.log(target.tagName + ' value is: ' + target.value); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class NameService { | |
private name; | |
constructor() { | |
this.name = "AngularJS Vienna"; | |
} | |
getName() { | |
return this.name; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the demo code I used in a talk "Angular 2 - A First Look", given on 23/06/15 at the AngularJS Vienna meetup.