2016-06-08 19:38:52 -04:00
|
|
|
import {APP_BASE_HREF} from '@angular/common';
|
2016-06-02 20:30:40 -04:00
|
|
|
import {Component, ComponentRef} from '@angular/core';
|
2016-06-10 13:21:53 -04:00
|
|
|
import {bootstrap} from '@angular/platform-browser-dynamic';
|
2016-06-08 19:38:52 -04:00
|
|
|
import {CanReuse, ComponentInstruction, OnReuse, ROUTER_DIRECTIVES, RouteConfig, RouteParams} from '@angular/router-deprecated';
|
|
|
|
|
2015-10-05 19:37:31 -04:00
|
|
|
|
|
|
|
|
|
|
|
// #docregion reuseCmp
|
|
|
|
@Component({
|
|
|
|
selector: 'my-cmp',
|
|
|
|
template: `
|
|
|
|
<div>hello {{name}}!</div>
|
|
|
|
<div>message: <input id="message"></div>
|
|
|
|
`
|
|
|
|
})
|
|
|
|
class MyCmp implements CanReuse,
|
|
|
|
OnReuse {
|
|
|
|
name: string;
|
|
|
|
constructor(params: RouteParams) { this.name = params.get('name') || 'NOBODY'; }
|
|
|
|
|
refactor(lifecycle): prefix lifecycle methods with "ng"
BREAKING CHANGE:
Previously, components that would implement lifecycle interfaces would include methods
like "onChanges" or "afterViewInit." Given that components were at risk of using such
names without realizing that Angular would call the methods at different points of
the component lifecycle. This change adds an "ng" prefix to all lifecycle hook methods,
far reducing the risk of an accidental name collision.
To fix, just rename these methods:
* onInit
* onDestroy
* doCheck
* onChanges
* afterContentInit
* afterContentChecked
* afterViewInit
* afterViewChecked
* _Router Hooks_
* onActivate
* onReuse
* onDeactivate
* canReuse
* canDeactivate
To:
* ngOnInit,
* ngOnDestroy,
* ngDoCheck,
* ngOnChanges,
* ngAfterContentInit,
* ngAfterContentChecked,
* ngAfterViewInit,
* ngAfterViewChecked
* _Router Hooks_
* routerOnActivate
* routerOnReuse
* routerOnDeactivate
* routerCanReuse
* routerCanDeactivate
The names of lifecycle interfaces and enums have not changed, though interfaces
have been updated to reflect the new method names.
Closes #5036
2015-11-16 20:04:36 -05:00
|
|
|
routerCanReuse(next: ComponentInstruction, prev: ComponentInstruction) { return true; }
|
2015-10-05 19:37:31 -04:00
|
|
|
|
refactor(lifecycle): prefix lifecycle methods with "ng"
BREAKING CHANGE:
Previously, components that would implement lifecycle interfaces would include methods
like "onChanges" or "afterViewInit." Given that components were at risk of using such
names without realizing that Angular would call the methods at different points of
the component lifecycle. This change adds an "ng" prefix to all lifecycle hook methods,
far reducing the risk of an accidental name collision.
To fix, just rename these methods:
* onInit
* onDestroy
* doCheck
* onChanges
* afterContentInit
* afterContentChecked
* afterViewInit
* afterViewChecked
* _Router Hooks_
* onActivate
* onReuse
* onDeactivate
* canReuse
* canDeactivate
To:
* ngOnInit,
* ngOnDestroy,
* ngDoCheck,
* ngOnChanges,
* ngAfterContentInit,
* ngAfterContentChecked,
* ngAfterViewInit,
* ngAfterViewChecked
* _Router Hooks_
* routerOnActivate
* routerOnReuse
* routerOnDeactivate
* routerCanReuse
* routerCanDeactivate
The names of lifecycle interfaces and enums have not changed, though interfaces
have been updated to reflect the new method names.
Closes #5036
2015-11-16 20:04:36 -05:00
|
|
|
routerOnReuse(next: ComponentInstruction, prev: ComponentInstruction) {
|
2015-10-05 19:37:31 -04:00
|
|
|
this.name = next.params['name'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// #enddocregion
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'example-app',
|
|
|
|
template: `
|
|
|
|
<h1>Say hi to...</h1>
|
2015-11-23 19:02:19 -05:00
|
|
|
<a [routerLink]="['/HomeCmp', {name: 'naomi'}]" id="naomi-link">Naomi</a> |
|
|
|
|
<a [routerLink]="['/HomeCmp', {name: 'brad'}]" id="brad-link">Brad</a>
|
2015-10-05 19:37:31 -04:00
|
|
|
<router-outlet></router-outlet>
|
|
|
|
`,
|
|
|
|
directives: [ROUTER_DIRECTIVES]
|
|
|
|
})
|
|
|
|
@RouteConfig([
|
2015-10-25 05:30:27 -04:00
|
|
|
{path: '/', component: MyCmp, name: 'HomeCmp'},
|
|
|
|
{path: '/:name', component: MyCmp, name: 'HomeCmp'}
|
2015-10-05 19:37:31 -04:00
|
|
|
])
|
2016-04-28 20:50:03 -04:00
|
|
|
export class AppCmp {
|
2015-10-05 19:37:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-28 20:50:03 -04:00
|
|
|
export function main(): Promise<ComponentRef<AppCmp>> {
|
2016-06-08 19:38:52 -04:00
|
|
|
return bootstrap(
|
|
|
|
AppCmp, [{provide: APP_BASE_HREF, useValue: '/@angular/examples/router/ts/reuse'}]);
|
2015-10-05 19:37:31 -04:00
|
|
|
}
|