On Github ckknight / angular-2-0-presentation
by ckknight
@Annotation @AnotherAnnotation({ some: "data" }) class MyClass { methodA(name:string):int { var length:int = name.length; return length; } }
import * as rtts from 'rtts'; class MyClass { methodA(name) { rtts.types(name, rtts.string); var length = rtts.type(name.length, rtts.int); return rtts.returnType(length, rtts.int); } } MyClass.annotations = [ new Annotation(), new AnotherAnnotation({ some: "data" }) ]; MyClass.parameters = [{is:String}];
// AtScript Type metadata class Monkey { constructor(banana:Banana) { ... }}
// Type metadata Monkey.parameters = [{is:Banana}];
// AtScript Metadata Annotation @Inject(Banana) class Monkey { ... }
// Metadata Annotation Monkey.annotations = [new Inject(Banana)];
// By arbitrary string (not recommended) Monkey.annotations = [new Inject('banana')];
ng-value → [value] or bind-value
ng-click → (click) or on-click
<elm value="data"> meanselm.setAttribute('value', 'data');
<elm [value]="data"> meanselm.value = 'data';
<elm (click)="doSomething()"> meanselm.addEventHandler('click', parse("doSomething()"));
<div> <input type="text" [value]="newTodoTitle"> <button (click)="addTodo()">+</button> <tab-container> <tab-pane title="Good kids"> <div [ng-repeat|todo]="todosOf('good')"> <input type="checkbox" [checked]="todo.done"> {{todo.title}} <button (click)="deleteTodo(todo)"> X </button> </div> </tab-pane> </tab-container> </div>
@Component({ selector: 'hello-app', template: new TemplateConfig({ inline: "<div>${message}</div>", }) }) class HelloCmp { constructor(service: MyService) { this.service = service; this.message = service.getMessage(); } }
@Decorator({ selector: '[cornflower-blue]' }) class CornflowerBlue { constructor(element: HTMLElement) { element.style.color = '#6495ed'; } }
class MyService { getMessage() { return "Hello!"; } }