On Github timruffles / angular-2-alpha
Angular 2 is still in the works. The core concepts are solid, but the API may change
Victor Savkin, 12th Oct.
Fiber launched this week as Google's first Angular 2 application. https://t.co/CgOIiuq13U pic.twitter.com/hsKlpHA4y6
— Brad Green (@bradlygreen) November 20, 2015import { Component } from 'angular2/angular2'; export { HelloComponent }; @Component({ selector: 'hello-angular', template: '<h1>{{ message }}</h1>', }) class HelloComponent { constructor() { this.message = "Hi there"; } }
import { Component } from 'angular2/angular2';
export { HelloComponent };
@Component({ // any CSS selector selector: 'hello-angular', // ... })
@Component({ // ... template: '<h1>{{ message }}</h1>', })
class HelloComponent { constructor() { this.message = "Hi there"; } }
import { Component } from 'angular2/angular2'; export { HelloComponent }; @Component({ selector: 'hello-angular', template: '<h1>{{ message }}</h1>', }) class HelloComponent { constructor() { this.message = "Hi there"; } }
import { HelloComponent } from "./HelloComponent"; import { bootstrap } from "angular2/angular2"; bootstrap(HelloComponent);
<!DOCTYPE html> <hello-component></hello-component> <!-- with a production bundle --> <script src="dist/app.js"></script>
import { Component } from 'angular2/angular2'; import { HelloComponent } from './HelloComponent'; export { FrontPage }; @Component({ selector: 'front-page', directives: [HelloComponent], template: '<hello-angular></hello-angular>', }) class FrontPage { }
import { Component, FORM_DIRECTIVES, CORE_DIRECTIVES } from 'angular2/angular2'; @Component({ directives: [FORM_DIRECTIVES, CORE_DIRECTIVES], // ... })
<!-- like ng 1 - interpolated --> <div title="Hello {{ person }}"> <!-- whole attribute --> <div [title]="getMessage()">
<div [title]="getMessage() | toTitle">
<!-- DOM events --> <form (submit)="create($event)">
<!-- the local ourName property will be two way bound to <code>name</code> of our some-editor component --> <some-editor ([name])="ourName">
<video #movieplayer > <button (click)="movieplayer.play()"> </video>
module.service("User", calledWithNew); module.factory("User", usesReturnValue); module.provider("User", returnsProviderConfig); module.value("User", User);
module.controller("UserCtrl", function( User , Login , errors ) { // unclear where the above came from physically // (without conventions) })
export { Greeter }; class Greeter { message(name) { return 'Hello ${name}, Angular 2 is easy'; } }
import { Component } from 'angular2/angular2'; import { Greeter } from './greeter'; @Component({ // setup providers: [Greeter], }) class HelloComponent { constructor(greeter: Greeter) { this.message = greeter.message(); } }
import { Greeter } from './greeter'; bootstrap(FrontPage, [Greeter]);
import { Greeter } from './greeter'; @Component({ // don't be explicit providers: [], }) class HelloComponent { constructor(greeter: Greeter) { } }
// rought version of ng-click el.on("click", function(event) { $scope.$apply(function() { $scope.$eval(userCallback, { $event: event, }); }); });
@Component({ selector: 'toggler', template: '<button (click)="toggle()"> {{ msg }}</button>', }) class TogglerComponent { constructor() { this.msg = "Click me"; } toggle() { this.msg = "You clicked me!"; setTimeout(() => { this.msg = "Click me"; }, 250); } }
Zones patch all async:
window.setTimeout = function(fn, timeout) { originalTimeout(zone.callback(fn), timeout); }