(docs) template-syntax - to alpha46, noImplicitAny, demo enum binding

closes #374
This commit is contained in:
Ward Bell 2015-11-13 13:22:37 -08:00
parent 54573563a3
commit e7a9a46994
5 changed files with 45 additions and 28 deletions

View File

@ -11,7 +11,7 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"angular2": "2.0.0-alpha.44", "angular2": "2.0.0-alpha.46",
"systemjs": "0.19.2" "systemjs": "0.19.2"
}, },
"devDependencies": { "devDependencies": {

View File

@ -374,3 +374,10 @@ See console log
<!-- ohficFax refers to the input element; pass its `value` to an event handler --> <!-- ohficFax refers to the input element; pass its `value` to an event handler -->
<input var-ohfice-fax placeholder="phone number"> <input var-ohfice-fax placeholder="phone number">
<button (click)="callFax(ohficeFax.value)">Fax</button> <button (click)="callFax(ohficeFax.value)">Fax</button>
<!-- enums in bindings -->
<hr>
<h2>Enums in bindings </h2>
<p>The name of the Color.Red enum is {{Color[Color.Red]}}</p>
<p>The current color number is {{color}}</p>
<p><button [style.color]="Color[color]" (click)="colorToggle()">Enum Toggle</button>

View File

@ -12,7 +12,7 @@ import {bootstrap, Component, CORE_DIRECTIVES,
Input, Output, Input, Output,
Directive, Directive,
ElementRef, EventEmitter, ElementRef, EventEmitter,
FORM_DIRECTIVES NgForm, FORM_DIRECTIVES
} from 'angular2/angular2'; } from 'angular2/angular2';
class Hero { class Hero {
@ -78,7 +78,7 @@ class HeroDetailComponent {
hero: Hero; hero: Hero;
@Output() @Output()
deleted = new EventEmitter(); deleted = new EventEmitter<Hero>();
onDelete() { onDelete() {
this.deleted.next(this.hero); this.deleted.next(this.hero);
@ -121,8 +121,8 @@ class LoopbackComponent {
}) })
class KeyUpComponent { class KeyUpComponent {
values=''; values='';
onKey(event) { onKey(event:KeyboardEvent) {
this.values += event.target.value + ' | '; this.values += (<HTMLInputElement>event.target).value + ' | ';
} }
} }
@ -136,7 +136,7 @@ class KeyUpComponent {
}) })
class KeyUpComponentV2 { class KeyUpComponentV2 {
values=''; values='';
onKey(value) { onKey(value:string) {
this.values += value + ' | '; this.values += value + ' | ';
} }
} }
@ -157,8 +157,10 @@ class KeyUpComponentV3 {
selector: 'little-tour', selector: 'little-tour',
template: ` template: `
<h4>Little Tour of Heroes</h4> <h4>Little Tour of Heroes</h4>
<input #new-hero (keyup.enter)="addHero(newHero)"> <input #box
<button (click)=addHero(newHero)>Add</button> (keyup.enter)="addHero(box.value)"
(blur)="addHero(box.value)">
<button (click)=addHero(box.value)>Add</button>
<ul><li *ng-for="#hero of heroes">{{hero}}</li></ul> <ul><li *ng-for="#hero of heroes">{{hero}}</li></ul>
`, `,
directives: [CORE_DIRECTIVES] directives: [CORE_DIRECTIVES]
@ -166,16 +168,18 @@ class KeyUpComponentV3 {
class LittleTour { class LittleTour {
heroes=['Windstorm', 'Bombasto', 'Magneta', 'Tornado']; heroes=['Windstorm', 'Bombasto', 'Magneta', 'Tornado'];
addHero(newHero) { addHero(newHero:string) {
if (newHero.value) { if (newHero) {
this.heroes.push(newHero.value); this.heroes.push(newHero);
newHero.value = null; // clear the newHero textbox newHero = null; // clear the newHero textbox
} }
} }
} }
bootstrap(LittleTour); bootstrap(LittleTour);
enum Color {Red, Green, Blue};
@Component({ @Component({
selector: 'my-app', selector: 'my-app',
templateUrl: 'app/app.html', templateUrl: 'app/app.html',
@ -194,9 +198,13 @@ class AppComponent {
callPhone(value:string) {alert(`Calling ${value} ...`)} callPhone(value:string) {alert(`Calling ${value} ...`)}
canSave = true; canSave = true;
Color = Color;
color = Color.Red;
colorToggle() {this.color = (this.color === Color.Red)? Color.Blue : Color.Red}
currentHero = Hero.MockHeroes[0]; currentHero = Hero.MockHeroes[0];
getStyles(el){ getStyles(el:Element){
let styles = window.getComputedStyle(el); let styles = window.getComputedStyle(el);
let showStyles = {}; let showStyles = {};
for (var p in this.setStyles()){ for (var p in this.setStyles()){
@ -220,26 +228,26 @@ class AppComponent {
nullHero:Hero = null; // or undefined nullHero:Hero = null; // or undefined
onCancel(event){ onCancel(event:KeyboardEvent){
let evtMsg = event ? ' Event target is '+ event.target.innerHTML : ''; let evtMsg = event ? ' Event target is '+ (<HTMLElement>event.target).innerHTML : '';
alert('Canceled.'+evtMsg) alert('Canceled.'+evtMsg)
} }
onClickMe(event){ onClickMe(event:KeyboardEvent){
let evtMsg = event ? ' Event target class is '+ event.target.className : ''; let evtMsg = event ? ' Event target class is '+ (<HTMLElement>event.target).className : '';
alert('Click me.'+evtMsg) alert('Click me.'+evtMsg)
} }
onDeleted(hero){ onDeleted(hero:Hero){
alert('Deleted hero: '+ (hero && hero.firstName)) alert('Deleted hero: '+ (hero && hero.firstName))
} }
onSave(event){ onSave(event:KeyboardEvent){
let evtMsg = event ? ' Event target is '+ event.target.innerText : ''; let evtMsg = event ? ' Event target is '+ (<HTMLElement>event.target).innerText : '';
alert('Saved.'+evtMsg) alert('Saved.'+evtMsg)
} }
onSubmit(form){ onSubmit(form:NgForm){
let evtMsg = form.valid ? let evtMsg = form.valid ?
' Form value is '+ JSON.stringify(form.value) : ' Form value is '+ JSON.stringify(form.value) :
' Form is invalid'; ' Form is invalid';
@ -251,9 +259,9 @@ class AppComponent {
price: 42 price: 42
}; };
setLastName(event){ setLastName(lastName:string){
console.log(event); console.log(lastName);
this.currentHero.lastName = event; this.currentHero.lastName = lastName;
} }
setClasses() { setClasses() {
@ -272,10 +280,11 @@ class AppComponent {
} }
} }
toeChoice(picker){ toeChoice(picker:HTMLFieldSetElement){
let choices = picker.children; let choices = picker.children;
for (let i=0; i<choices.length; i++){ for (let i=0; i<choices.length; i++){
if (choices[i].checked) {return choices[i].value} var choice = <HTMLInputElement>choices[i];
if (choice.checked) {return choice.value}
} }
} }

View File

@ -6,6 +6,7 @@
"emitDecoratorMetadata": true, "emitDecoratorMetadata": true,
"experimentalDecorators": true, "experimentalDecorators": true,
"removeComments": false, "removeComments": false,
"noImplicitAny": false "noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
} }
} }

View File

@ -1181,7 +1181,7 @@ code-example(format="" language="html").
hero: Hero; hero: Hero;
@Output() @Output()
deleted = new EventEmitter(); deleted = new EventEmitter<Hero>();
onDelete() { onDelete() {
this.deleted.next(this.hero); this.deleted.next(this.hero);