forked from thelgevold/angular-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
69 lines (54 loc) · 2.03 KB
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
///<reference path="node_modules/angular2/typings/browser.d.ts"/>
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/delay';
import 'rxjs/add/operator/mergeMap';
import 'rxjs/add/observable/interval';
import 'rxjs/add/observable/forkJoin';
import {HTTP_PROVIDERS} from 'angular2/http';
import {Component, provide} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';
import {DemoPage} from './demo-page';
import {About} from './components/about/about';
import {ROUTER_DIRECTIVES, RouteConfig, Location,ROUTER_PROVIDERS, LocationStrategy, HashLocationStrategy, Route, AsyncRoute, Router, AuxRoute} from 'angular2/router';
import {AddressBookTitleService} from './components/dependency-injection/address-book-title-service';
import {Message} from './components/aux-route/message';
declare var System:any;
@Component(
{
selector: 'demo-app',
templateUrl: './demo-app.html',
directives:[ROUTER_DIRECTIVES]
})
@RouteConfig([
new Route({path: '/', component: About, name: 'About', data: {project: 'angular-2-samples'}}),
new Route({path: '/demo/...', component: DemoPage, name: 'Demo'}),
new AuxRoute({ path: '/msg', component:Message, name: 'Msg'}),
new AsyncRoute({
path: '/lazy',
loader: () => ComponentHelper.LoadComponentAsync('LazyLoaded','./components/lazy-loaded/lazy-loaded'),
name: 'Lazy'
})
])
class MyDemoApp {
router: Router;
location: Location;
constructor(router: Router, location: Location) {
this.router = router;
this.location = location;
}
getLinkStyle(path) {
if(path === this.location.path()){
return true;
}
else if(path.length > 0){
return this.location.path().indexOf(path) > -1;
}
}
}
class ComponentHelper{
static LoadComponentAsync(name,path){
return System.import(path).then(c => c[name]);
}
}
bootstrap(MyDemoApp,[AddressBookTitleService,ROUTER_PROVIDERS, HTTP_PROVIDERS,
provide(LocationStrategy, {useClass: HashLocationStrategy})]);