feat(router): update the example app to use lazily-loaded modules

This commit is contained in:
vsavkin 2016-07-06 11:02:36 -07:00
parent 8ebb8e44c8
commit 6fbe56dbf2
3 changed files with 38 additions and 16 deletions

View File

@ -89,19 +89,6 @@ export class DbService {
}
}
@Component(
{selector: 'inbox-detail', directives: ROUTER_DIRECTIVES, templateUrl: 'app/inbox-detail.html'})
export class InboxDetailCmp {
private record: InboxRecord = new InboxRecord();
private ready: boolean = false;
constructor(db: DbService, route: ActivatedRoute) {
route.params.forEach(p => {
PromiseWrapper.then(db.email(p['id']), (data) => { this.record.setData(data); });
});
}
}
@Component({selector: 'inbox', templateUrl: 'app/inbox.html', directives: ROUTER_DIRECTIVES})
export class InboxCmp {
private items: InboxRecord[] = [];
@ -146,13 +133,14 @@ export const ROUTER_CONFIG = [
{path: '', terminal: true, redirectTo: 'inbox'},
{path: 'inbox', component: InboxCmp},
{path: 'drafts', component: DraftsCmp},
{path: 'detail/:id', component: InboxDetailCmp}
{path: 'detail', mountChildren: 'app/inbox-detail.js' }
];
@Component({
selector: 'inbox-app',
viewProviders: [DbService],
templateUrl: 'app/inbox-app.html',
directives: ROUTER_DIRECTIVES
directives: ROUTER_DIRECTIVES,
precompile: [InboxCmp, DraftsCmp]
})
export class InboxApp {}

View File

@ -0,0 +1,31 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {Component, AppModule} from '@angular/core';
import {ROUTER_DIRECTIVES, ActivatedRoute, provideRoutes} from '@angular/router';
import {PromiseWrapper} from '@angular/core/src/facade/async';
import {InboxRecord, DbService} from './inbox-app';
@Component(
{selector: 'inbox-detail', directives: ROUTER_DIRECTIVES, templateUrl: 'app/inbox-detail.html'})
export class InboxDetailCmp {
private record: InboxRecord = new InboxRecord();
private ready: boolean = false;
constructor(db: DbService, route: ActivatedRoute) {
route.params.forEach(p => {
PromiseWrapper.then(db.email(p['id']), (data) => { this.record.setData(data); });
});
}
}
@AppModule({
providers: [provideRoutes([{path: ':id', component: InboxDetailCmp}])],
precompile: [InboxDetailCmp]
})
export default class InboxDetailModule {}

View File

@ -12,5 +12,8 @@ import {HashLocationStrategy, LocationStrategy} from '@angular/common';
import {provideRouter} from '@angular/router';
export function main() {
bootstrap(InboxApp, [provideRouter(ROUTER_CONFIG), {provide: LocationStrategy, useClass: HashLocationStrategy}]);
bootstrap(InboxApp, [
provideRouter(ROUTER_CONFIG),
{provide: LocationStrategy, useClass: HashLocationStrategy}
]);
}