Created
September 1, 2015 07:55
-
-
Save shuhei/81af7d13782cd07324a3 to your computer and use it in GitHub Desktop.
angular2 alpha.35 router example
This file contains hidden or 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
import { bind } from 'angular2/di'; | |
import { Component, View, bootstrap } from 'angular2/angular2'; | |
import { Route, Router, RouteConfig, RouteParams, LocationStrategy, HashLocationStrategy, routerInjectables, routerDirectives } from 'angular2/router'; | |
@Component({ | |
selector: 'hello' | |
}) | |
@View({ | |
template: `<p>Hello, {{ name }}!</p>` | |
}) | |
class Hello { | |
constructor() { | |
this.name = 'Angular'; | |
} | |
} | |
@Component({ | |
selector: 'ciao' | |
}) | |
@View({ | |
template: `<p>Ciao, {{ name }}!</p>` | |
}) | |
class Hello { | |
constructor() { | |
this.name = 'Angular'; | |
} | |
} | |
@Component({ | |
selector: 'hello-app' | |
}) | |
@View({ | |
directives: [Hello, routerDirectives], | |
template: ` | |
<ul> | |
<li><a [router-link]="['/hello']">Hello</a></li> | |
<li><a [router-link]="['/ciao']">Ciao</a></li> | |
</ul> | |
<router-outlet></router-outlet> | |
` | |
}) | |
@RouteConfig([ | |
new Route({ path: '/', component: Hello, as: 'hello' }), | |
new Route({ path: '/ciao', component: Ciao, as: 'ciao' }) | |
]) | |
class HelloApp { | |
constructor() { | |
} | |
} | |
bootstrap(HelloApp, [ | |
routerInjectables, | |
bind(LocationStrategy).toClass(HashLocationStrategy) | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment