feat(router): update the example app to use lazily-loaded modules
This commit is contained in:
parent
8ebb8e44c8
commit
6fbe56dbf2
|
@ -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})
|
@Component({selector: 'inbox', templateUrl: 'app/inbox.html', directives: ROUTER_DIRECTIVES})
|
||||||
export class InboxCmp {
|
export class InboxCmp {
|
||||||
private items: InboxRecord[] = [];
|
private items: InboxRecord[] = [];
|
||||||
|
@ -146,13 +133,14 @@ export const ROUTER_CONFIG = [
|
||||||
{path: '', terminal: true, redirectTo: 'inbox'},
|
{path: '', terminal: true, redirectTo: 'inbox'},
|
||||||
{path: 'inbox', component: InboxCmp},
|
{path: 'inbox', component: InboxCmp},
|
||||||
{path: 'drafts', component: DraftsCmp},
|
{path: 'drafts', component: DraftsCmp},
|
||||||
{path: 'detail/:id', component: InboxDetailCmp}
|
{path: 'detail', mountChildren: 'app/inbox-detail.js' }
|
||||||
];
|
];
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'inbox-app',
|
selector: 'inbox-app',
|
||||||
viewProviders: [DbService],
|
viewProviders: [DbService],
|
||||||
templateUrl: 'app/inbox-app.html',
|
templateUrl: 'app/inbox-app.html',
|
||||||
directives: ROUTER_DIRECTIVES
|
directives: ROUTER_DIRECTIVES,
|
||||||
|
precompile: [InboxCmp, DraftsCmp]
|
||||||
})
|
})
|
||||||
export class InboxApp {}
|
export class InboxApp {}
|
||||||
|
|
|
@ -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 {}
|
|
@ -12,5 +12,8 @@ import {HashLocationStrategy, LocationStrategy} from '@angular/common';
|
||||||
import {provideRouter} from '@angular/router';
|
import {provideRouter} from '@angular/router';
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
bootstrap(InboxApp, [provideRouter(ROUTER_CONFIG), {provide: LocationStrategy, useClass: HashLocationStrategy}]);
|
bootstrap(InboxApp, [
|
||||||
|
provideRouter(ROUTER_CONFIG),
|
||||||
|
{provide: LocationStrategy, useClass: HashLocationStrategy}
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue