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
This commit is contained in:
@ -106,21 +106,21 @@ function ngOutletDirective($animate, $q: ng.IQService, $router) {
|
|||||||
let next = $q.when(true);
|
let next = $q.when(true);
|
||||||
let previousInstruction = this.currentInstruction;
|
let previousInstruction = this.currentInstruction;
|
||||||
this.currentInstruction = instruction;
|
this.currentInstruction = instruction;
|
||||||
if (this.currentController && this.currentController.$onReuse) {
|
if (this.currentController && this.currentController.$routerOnReuse) {
|
||||||
next = $q.when(
|
next = $q.when(
|
||||||
this.currentController.$onReuse(this.currentInstruction, previousInstruction));
|
this.currentController.$routerOnReuse(this.currentInstruction, previousInstruction));
|
||||||
}
|
}
|
||||||
|
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
canReuse(nextInstruction) {
|
routerCanReuse(nextInstruction) {
|
||||||
let result;
|
let result;
|
||||||
if (!this.currentInstruction ||
|
if (!this.currentInstruction ||
|
||||||
this.currentInstruction.componentType !== nextInstruction.componentType) {
|
this.currentInstruction.componentType !== nextInstruction.componentType) {
|
||||||
result = false;
|
result = false;
|
||||||
} else if (this.currentController && this.currentController.$canReuse) {
|
} else if (this.currentController && this.currentController.$routerCanReuse) {
|
||||||
result = this.currentController.$canReuse(nextInstruction, this.currentInstruction);
|
result = this.currentController.$routerCanReuse(nextInstruction, this.currentInstruction);
|
||||||
} else {
|
} else {
|
||||||
result = nextInstruction === this.currentInstruction ||
|
result = nextInstruction === this.currentInstruction ||
|
||||||
angular.equals(nextInstruction.params, this.currentInstruction.params);
|
angular.equals(nextInstruction.params, this.currentInstruction.params);
|
||||||
@ -128,18 +128,18 @@ function ngOutletDirective($animate, $q: ng.IQService, $router) {
|
|||||||
return $q.when(result);
|
return $q.when(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
canDeactivate(instruction) {
|
routerCanDeactivate(instruction) {
|
||||||
if (this.currentController && this.currentController.$canDeactivate) {
|
if (this.currentController && this.currentController.$routerCanDeactivate) {
|
||||||
return $q.when(
|
return $q.when(
|
||||||
this.currentController.$canDeactivate(instruction, this.currentInstruction));
|
this.currentController.$routerCanDeactivate(instruction, this.currentInstruction));
|
||||||
}
|
}
|
||||||
return $q.when(true);
|
return $q.when(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
deactivate(instruction) {
|
deactivate(instruction) {
|
||||||
if (this.currentController && this.currentController.$onDeactivate) {
|
if (this.currentController && this.currentController.$routerOnDeactivate) {
|
||||||
return $q.when(
|
return $q.when(
|
||||||
this.currentController.$onDeactivate(instruction, this.currentInstruction));
|
this.currentController.$routerOnDeactivate(instruction, this.currentInstruction));
|
||||||
}
|
}
|
||||||
return $q.when();
|
return $q.when();
|
||||||
}
|
}
|
||||||
@ -172,8 +172,8 @@ function ngOutletDirective($animate, $q: ng.IQService, $router) {
|
|||||||
// by debug mode
|
// by debug mode
|
||||||
this.currentController = this.currentElement.children().eq(0).controller(componentName);
|
this.currentController = this.currentElement.children().eq(0).controller(componentName);
|
||||||
|
|
||||||
if (this.currentController && this.currentController.$onActivate) {
|
if (this.currentController && this.currentController.$routerOnActivate) {
|
||||||
return this.currentController.$onActivate(instruction, previousInstruction);
|
return this.currentController.$routerOnActivate(instruction, previousInstruction);
|
||||||
}
|
}
|
||||||
return $q.when();
|
return $q.when();
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ describe('ngOutlet animations', function () {
|
|||||||
function registerComponent(name, options) {
|
function registerComponent(name, options) {
|
||||||
var controller = options.controller || function () {};
|
var controller = options.controller || function () {};
|
||||||
|
|
||||||
['$onActivate', '$onDeactivate', '$onReuse', '$canReuse', '$canDeactivate'].forEach(function (hookName) {
|
['$routerOnActivate', '$routerOnDeactivate', '$routerOnReuse', '$routerCanReuse', '$routerCanDeactivate'].forEach(function (hookName) {
|
||||||
if (options[hookName]) {
|
if (options[hookName]) {
|
||||||
controller.prototype[hookName] = options[hookName];
|
controller.prototype[hookName] = options[hookName];
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ describe('Navigation lifecycle', function () {
|
|||||||
var spy = jasmine.createSpy('activate');
|
var spy = jasmine.createSpy('activate');
|
||||||
registerComponent('activateCmp', {
|
registerComponent('activateCmp', {
|
||||||
template: '<p>hello</p>',
|
template: '<p>hello</p>',
|
||||||
$onActivate: spy
|
$routerOnActivate: spy
|
||||||
});
|
});
|
||||||
|
|
||||||
$router.config([
|
$router.config([
|
||||||
@ -53,7 +53,7 @@ describe('Navigation lifecycle', function () {
|
|||||||
it('should pass instruction into the activate hook of a controller', function () {
|
it('should pass instruction into the activate hook of a controller', function () {
|
||||||
var spy = jasmine.createSpy('activate');
|
var spy = jasmine.createSpy('activate');
|
||||||
registerComponent('userCmp', {
|
registerComponent('userCmp', {
|
||||||
$onActivate: spy
|
$routerOnActivate: spy
|
||||||
});
|
});
|
||||||
|
|
||||||
$router.config([
|
$router.config([
|
||||||
@ -72,7 +72,7 @@ describe('Navigation lifecycle', function () {
|
|||||||
var spy = jasmine.createSpy('activate');
|
var spy = jasmine.createSpy('activate');
|
||||||
var activate = registerComponent('activateCmp', {
|
var activate = registerComponent('activateCmp', {
|
||||||
template: 'hi',
|
template: 'hi',
|
||||||
$onActivate: spy
|
$routerOnActivate: spy
|
||||||
});
|
});
|
||||||
|
|
||||||
$router.config([
|
$router.config([
|
||||||
@ -113,7 +113,7 @@ describe('Navigation lifecycle', function () {
|
|||||||
it('should run the deactivate hook of controllers', function () {
|
it('should run the deactivate hook of controllers', function () {
|
||||||
var spy = jasmine.createSpy('deactivate');
|
var spy = jasmine.createSpy('deactivate');
|
||||||
registerComponent('deactivateCmp', {
|
registerComponent('deactivateCmp', {
|
||||||
$onDeactivate: spy
|
$routerOnDeactivate: spy
|
||||||
});
|
});
|
||||||
|
|
||||||
$router.config([
|
$router.config([
|
||||||
@ -133,7 +133,7 @@ describe('Navigation lifecycle', function () {
|
|||||||
it('should pass instructions into the deactivate hook of controllers', function () {
|
it('should pass instructions into the deactivate hook of controllers', function () {
|
||||||
var spy = jasmine.createSpy('deactivate');
|
var spy = jasmine.createSpy('deactivate');
|
||||||
registerComponent('deactivateCmp', {
|
registerComponent('deactivateCmp', {
|
||||||
$onDeactivate: spy
|
$routerOnDeactivate: spy
|
||||||
});
|
});
|
||||||
|
|
||||||
$router.config([
|
$router.config([
|
||||||
@ -155,13 +155,13 @@ describe('Navigation lifecycle', function () {
|
|||||||
var log = [];
|
var log = [];
|
||||||
|
|
||||||
registerComponent('activateCmp', {
|
registerComponent('activateCmp', {
|
||||||
$onActivate: function () {
|
$routerOnActivate: function () {
|
||||||
log.push('activate');
|
log.push('activate');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
registerComponent('deactivateCmp', {
|
registerComponent('deactivateCmp', {
|
||||||
$onDeactivate: function () {
|
$routerOnDeactivate: function () {
|
||||||
log.push('deactivate');
|
log.push('deactivate');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -180,7 +180,7 @@ describe('Navigation lifecycle', function () {
|
|||||||
expect(log).toEqual(['deactivate', 'activate']);
|
expect(log).toEqual(['deactivate', 'activate']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reuse a component when the canReuse hook returns true', function () {
|
it('should reuse a component when the routerCanReuse hook returns true', function () {
|
||||||
var log = [];
|
var log = [];
|
||||||
var cmpInstanceCount = 0;
|
var cmpInstanceCount = 0;
|
||||||
|
|
||||||
@ -195,10 +195,10 @@ describe('Navigation lifecycle', function () {
|
|||||||
{path: '/b', component: 'twoCmp'}
|
{path: '/b', component: 'twoCmp'}
|
||||||
],
|
],
|
||||||
controller: ReuseCmp,
|
controller: ReuseCmp,
|
||||||
$canReuse: function () {
|
$routerCanReuse: function () {
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
$onReuse: function (next, prev) {
|
$routerOnReuse: function (next, prev) {
|
||||||
log.push('reuse: ' + prev.urlPath + ' -> ' + next.urlPath);
|
log.push('reuse: ' + prev.urlPath + ' -> ' + next.urlPath);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -223,7 +223,7 @@ describe('Navigation lifecycle', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should not reuse a component when the canReuse hook returns false', function () {
|
it('should not reuse a component when the routerCanReuse hook returns false', function () {
|
||||||
var log = [];
|
var log = [];
|
||||||
var cmpInstanceCount = 0;
|
var cmpInstanceCount = 0;
|
||||||
|
|
||||||
@ -237,10 +237,10 @@ describe('Navigation lifecycle', function () {
|
|||||||
{path: '/b', component: 'twoCmp'}
|
{path: '/b', component: 'twoCmp'}
|
||||||
],
|
],
|
||||||
controller: NeverReuseCmp,
|
controller: NeverReuseCmp,
|
||||||
$canReuse: function () {
|
$routerCanReuse: function () {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
$onReuse: function (next, prev) {
|
$routerOnReuse: function (next, prev) {
|
||||||
log.push('reuse: ' + prev.urlPath + ' -> ' + next.urlPath);
|
log.push('reuse: ' + prev.urlPath + ' -> ' + next.urlPath);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -271,7 +271,7 @@ describe('Navigation lifecycle', function () {
|
|||||||
var spy = jasmine.createSpy('activate');
|
var spy = jasmine.createSpy('activate');
|
||||||
registerComponent('activateCmp', {
|
registerComponent('activateCmp', {
|
||||||
$canActivate: canActivateSpy,
|
$canActivate: canActivateSpy,
|
||||||
$onActivate: spy
|
$routerOnActivate: spy
|
||||||
});
|
});
|
||||||
|
|
||||||
$router.config([
|
$router.config([
|
||||||
@ -293,7 +293,7 @@ describe('Navigation lifecycle', function () {
|
|||||||
registerComponent('activateCmp', {
|
registerComponent('activateCmp', {
|
||||||
template: 'hi',
|
template: 'hi',
|
||||||
$canActivate: canActivateSpy,
|
$canActivate: canActivateSpy,
|
||||||
$onActivate: activateSpy
|
$routerOnActivate: activateSpy
|
||||||
});
|
});
|
||||||
|
|
||||||
$router.config([
|
$router.config([
|
||||||
@ -317,7 +317,7 @@ describe('Navigation lifecycle', function () {
|
|||||||
$canActivate: function () {
|
$canActivate: function () {
|
||||||
return $q.when(true);
|
return $q.when(true);
|
||||||
},
|
},
|
||||||
$onActivate: spy
|
$routerOnActivate: spy
|
||||||
});
|
});
|
||||||
|
|
||||||
$router.config([
|
$router.config([
|
||||||
@ -356,10 +356,10 @@ describe('Navigation lifecycle', function () {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('should not navigate when canDeactivate returns false', function () {
|
it('should not navigate when routerCanDeactivate returns false', function () {
|
||||||
registerComponent('activateCmp', {
|
registerComponent('activateCmp', {
|
||||||
template: 'hi',
|
template: 'hi',
|
||||||
$canDeactivate: function () {
|
$routerCanDeactivate: function () {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -380,10 +380,10 @@ describe('Navigation lifecycle', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should navigate when canDeactivate returns true', function () {
|
it('should navigate when routerCanDeactivate returns true', function () {
|
||||||
registerComponent('activateCmp', {
|
registerComponent('activateCmp', {
|
||||||
template: 'hi',
|
template: 'hi',
|
||||||
$canDeactivate: function () {
|
$routerCanDeactivate: function () {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -411,7 +411,7 @@ describe('Navigation lifecycle', function () {
|
|||||||
$canActivate: function () {
|
$canActivate: function () {
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
$onActivate: spy
|
$routerOnActivate: spy
|
||||||
});
|
});
|
||||||
|
|
||||||
$router.config([
|
$router.config([
|
||||||
@ -427,10 +427,10 @@ describe('Navigation lifecycle', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should pass instructions into the canDeactivate hook of controllers', function () {
|
it('should pass instructions into the routerCanDeactivate hook of controllers', function () {
|
||||||
var spy = jasmine.createSpy('canDeactivate').and.returnValue(true);
|
var spy = jasmine.createSpy('routerCanDeactivate').and.returnValue(true);
|
||||||
registerComponent('deactivateCmp', {
|
registerComponent('deactivateCmp', {
|
||||||
$canDeactivate: spy
|
$routerCanDeactivate: spy
|
||||||
});
|
});
|
||||||
|
|
||||||
$router.config([
|
$router.config([
|
||||||
@ -451,7 +451,7 @@ describe('Navigation lifecycle', function () {
|
|||||||
function registerComponent(name, options) {
|
function registerComponent(name, options) {
|
||||||
var controller = options.controller || function () {};
|
var controller = options.controller || function () {};
|
||||||
|
|
||||||
['$onActivate', '$onDeactivate', '$onReuse', '$canReuse', '$canDeactivate'].forEach(function (hookName) {
|
['$routerOnActivate', '$routerOnDeactivate', '$routerOnReuse', '$routerCanReuse', '$routerCanDeactivate'].forEach(function (hookName) {
|
||||||
if (options[hookName]) {
|
if (options[hookName]) {
|
||||||
controller.prototype[hookName] = options[hookName];
|
controller.prototype[hookName] = options[hookName];
|
||||||
}
|
}
|
||||||
|
@ -230,7 +230,7 @@ describe('navigation', function () {
|
|||||||
function registerComponent(name, options) {
|
function registerComponent(name, options) {
|
||||||
var controller = options.controller || function () {};
|
var controller = options.controller || function () {};
|
||||||
|
|
||||||
['$onActivate', '$onDeactivate', '$onReuse', '$canReuse', '$canDeactivate'].forEach(function (hookName) {
|
['$routerOnActivate', '$routerOnDeactivate', '$routerOnReuse', '$routerCanReuse', '$routerCanDeactivate'].forEach(function (hookName) {
|
||||||
if (options[hookName]) {
|
if (options[hookName]) {
|
||||||
controller.prototype[hookName] = options[hookName];
|
controller.prototype[hookName] = options[hookName];
|
||||||
}
|
}
|
||||||
|
@ -10,40 +10,40 @@ The class constructor is called before any other lifecycle hook. Use it to injec
|
|||||||
|
|
||||||
|
|
||||||
@cheatsheetItem
|
@cheatsheetItem
|
||||||
`onChanges(changeRecord) { ... }`|`onChanges(changeRecord)`
|
`ngOnChanges(changeRecord) { ... }`|`ngOnChanges(changeRecord)`
|
||||||
Called after every change to input properties and before processing content or child views.
|
Called after every change to input properties and before processing content or child views.
|
||||||
|
|
||||||
|
|
||||||
@cheatsheetItem
|
@cheatsheetItem
|
||||||
`onInit() { ... }`|`onInit()`
|
`ngOnInit() { ... }`|`ngOnInit()`
|
||||||
Called after the constructor, initializing input properties, and the first call to onChanges.
|
Called after the constructor, initializing input properties, and the first call to ngOnChanges.
|
||||||
|
|
||||||
|
|
||||||
@cheatsheetItem
|
@cheatsheetItem
|
||||||
`doCheck() { ... }`|`doCheck()`
|
`ngDoCheck() { ... }`|`ngDoCheck()`
|
||||||
Called every time that the input properties of a component or a directive are checked. Use it to extend change detection by performing a custom check.
|
Called every time that the input properties of a component or a directive are checked. Use it to extend change detection by performing a custom check.
|
||||||
|
|
||||||
|
|
||||||
@cheatsheetItem
|
@cheatsheetItem
|
||||||
`afterContentInit() { ... }`|`afterContentInit()`
|
`ngAfterContentInit() { ... }`|`ngAfterContentInit()`
|
||||||
Called after onInit when the component's or directive's content has been initialized.
|
Called after ngOnInit when the component's or directive's content has been initialized.
|
||||||
|
|
||||||
|
|
||||||
@cheatsheetItem
|
@cheatsheetItem
|
||||||
`afterContentChecked() { ... }`|`afterContentChecked()`
|
`ngAfterContentChecked() { ... }`|`ngAfterContentChecked()`
|
||||||
Called after every check of the component's or directive's content.
|
Called after every check of the component's or directive's content.
|
||||||
|
|
||||||
|
|
||||||
@cheatsheetItem
|
@cheatsheetItem
|
||||||
`afterViewInit() { ... }`|`afterViewInit()`
|
`ngAfterViewInit() { ... }`|`ngAfterViewInit()`
|
||||||
Called after afterContentInit when the component's view has been initialized. Applies to components only.
|
Called after ngAfterContentInit when the component's view has been initialized. Applies to components only.
|
||||||
|
|
||||||
|
|
||||||
@cheatsheetItem
|
@cheatsheetItem
|
||||||
`afterViewChecked() { ... }`|`afterViewChecked()`
|
`ngAfterViewChecked() { ... }`|`ngAfterViewChecked()`
|
||||||
Called after every check of the component's view. Applies to components only.
|
Called after every check of the component's view. Applies to components only.
|
||||||
|
|
||||||
|
|
||||||
@cheatsheetItem
|
@cheatsheetItem
|
||||||
`onDestroy() { ... }`|`onDestroy()`
|
`ngOnDestroy() { ... }`|`ngOnDestroy()`
|
||||||
Called once, before the instance is destroyed.
|
Called once, before the instance is destroyed.
|
@ -31,25 +31,25 @@ A component decorator defining a function that the router should call first to d
|
|||||||
|
|
||||||
|
|
||||||
@cheatsheetItem
|
@cheatsheetItem
|
||||||
`onActivate(nextInstruction, prevInstruction) { ... }`|`onActivate`
|
`routerOnActivate(nextInstruction, prevInstruction) { ... }`|`routerOnActivate`
|
||||||
After navigating to a component, the router calls component's onActivate method (if defined).
|
After navigating to a component, the router calls component's routerOnActivate method (if defined).
|
||||||
|
|
||||||
|
|
||||||
@cheatsheetItem
|
@cheatsheetItem
|
||||||
`canReuse(nextInstruction, prevInstruction) { ... }`|`canReuse`
|
`routerCanReuse(nextInstruction, prevInstruction) { ... }`|`routerCanReuse`
|
||||||
The router calls a component's canReuse method (if defined) to determine whether to reuse the instance or destroy it and create a new instance. Should return a boolean or a promise.
|
The router calls a component's routerCanReuse method (if defined) to determine whether to reuse the instance or destroy it and create a new instance. Should return a boolean or a promise.
|
||||||
|
|
||||||
|
|
||||||
@cheatsheetItem
|
@cheatsheetItem
|
||||||
`onReuse(nextInstruction, prevInstruction) { ... }`|`onReuse`
|
`routerOnReuse(nextInstruction, prevInstruction) { ... }`|`routerOnReuse`
|
||||||
The router calls the component's onReuse method (if defined) when it re-uses a component instance.
|
The router calls the component's routerOnReuse method (if defined) when it re-uses a component instance.
|
||||||
|
|
||||||
|
|
||||||
@cheatsheetItem
|
@cheatsheetItem
|
||||||
`canDeactivate(nextInstruction, prevInstruction) { ... }`|`canDeactivate`
|
`routerCanDeactivate(nextInstruction, prevInstruction) { ... }`|`routerCanDeactivate`
|
||||||
The router calls the canDeactivate methods (if defined) of every component that would be removed after a navigation. The navigation proceeds if and only if all such methods return true or a promise that is resolved.
|
The router calls the routerCanDeactivate methods (if defined) of every component that would be removed after a navigation. The navigation proceeds if and only if all such methods return true or a promise that is resolved.
|
||||||
|
|
||||||
|
|
||||||
@cheatsheetItem
|
@cheatsheetItem
|
||||||
`onDeactivate(nextInstruction, prevInstruction) { ... }`|`onDeactivate`
|
`routerOnDeactivate(nextInstruction, prevInstruction) { ... }`|`routerOnDeactivate`
|
||||||
Called before the directive is removed as the result of a route change. May return a promise that pauses removing the directive until the promise resolves.
|
Called before the directive is removed as the result of a route change. May return a promise that pauses removing the directive until the promise resolves.
|
@ -8,7 +8,7 @@ import {
|
|||||||
APP_BASE_HREF
|
APP_BASE_HREF
|
||||||
} from 'angular2/router';
|
} from 'angular2/router';
|
||||||
|
|
||||||
// #docregion canDeactivate
|
// #docregion routerCanDeactivate
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'note-cmp',
|
selector: 'note-cmp',
|
||||||
template: `
|
template: `
|
||||||
@ -22,7 +22,7 @@ class NoteCmp implements CanDeactivate {
|
|||||||
|
|
||||||
constructor(params: RouteParams) { this.id = params.get('id'); }
|
constructor(params: RouteParams) { this.id = params.get('id'); }
|
||||||
|
|
||||||
canDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||||
return confirm('Are you sure you want to leave?');
|
return confirm('Are you sure you want to leave?');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Routing canDeactivate Lifecycle Example</title>
|
<title>Routing routerCanDeactivate Lifecycle Example</title>
|
||||||
<base href="/">
|
<base href="/">
|
||||||
|
|
||||||
<script src="http://cdn.rawgit.com/google/traceur-compiler/90da568c7aa8e53ea362db1fc211fbb4f65b5e94/bin/traceur-runtime.js"></script>
|
<script src="http://cdn.rawgit.com/google/traceur-compiler/90da568c7aa8e53ea362db1fc211fbb4f65b5e94/bin/traceur-runtime.js"></script>
|
||||||
|
@ -8,12 +8,12 @@ import {
|
|||||||
} from 'angular2/router';
|
} from 'angular2/router';
|
||||||
|
|
||||||
|
|
||||||
// #docregion onActivate
|
// #docregion routerOnActivate
|
||||||
@Component({selector: 'my-cmp', template: `<div>onActivate: {{log}}</div>`})
|
@Component({selector: 'my-cmp', template: `<div>routerOnActivate: {{log}}</div>`})
|
||||||
class MyCmp implements OnActivate {
|
class MyCmp implements OnActivate {
|
||||||
log: string = '';
|
log: string = '';
|
||||||
|
|
||||||
onActivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
routerOnActivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||||
this.log = `Finished navigating from "${prev ? prev.urlPath : 'null'}" to "${next.urlPath}"`;
|
this.log = `Finished navigating from "${prev ? prev.urlPath : 'null'}" to "${next.urlPath}"`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,18 +17,18 @@ describe('on activate example app', function() {
|
|||||||
waitForElement('my-cmp');
|
waitForElement('my-cmp');
|
||||||
|
|
||||||
expect(element(by.css('my-cmp')).getText())
|
expect(element(by.css('my-cmp')).getText())
|
||||||
.toContain('onActivate: Finished navigating from "null" to ""');
|
.toContain('routerOnActivate: Finished navigating from "null" to ""');
|
||||||
|
|
||||||
element(by.css('#param-link')).click();
|
element(by.css('#param-link')).click();
|
||||||
waitForElement('my-cmp');
|
waitForElement('my-cmp');
|
||||||
|
|
||||||
expect(element(by.css('my-cmp')).getText())
|
expect(element(by.css('my-cmp')).getText())
|
||||||
.toContain('onActivate: Finished navigating from "" to "1"');
|
.toContain('routerOnActivate: Finished navigating from "" to "1"');
|
||||||
|
|
||||||
browser.navigate().back();
|
browser.navigate().back();
|
||||||
waitForElement('my-cmp');
|
waitForElement('my-cmp');
|
||||||
|
|
||||||
expect(element(by.css('my-cmp')).getText())
|
expect(element(by.css('my-cmp')).getText())
|
||||||
.toContain('onActivate: Finished navigating from "1" to ""');
|
.toContain('routerOnActivate: Finished navigating from "1" to ""');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -16,12 +16,12 @@ class LogService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #docregion onDeactivate
|
// #docregion routerOnDeactivate
|
||||||
@Component({selector: 'my-cmp', template: `<div>hello</div>`})
|
@Component({selector: 'my-cmp', template: `<div>hello</div>`})
|
||||||
class MyCmp implements OnDeactivate {
|
class MyCmp implements OnDeactivate {
|
||||||
constructor(private logService: LogService) {}
|
constructor(private logService: LogService) {}
|
||||||
|
|
||||||
onDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
routerOnDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||||
this.logService.addLog(
|
this.logService.addLog(
|
||||||
`Navigating from "${prev ? prev.urlPath : 'null'}" to "${next.urlPath}"`);
|
`Navigating from "${prev ? prev.urlPath : 'null'}" to "${next.urlPath}"`);
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,9 @@ class MyCmp implements CanReuse,
|
|||||||
name: string;
|
name: string;
|
||||||
constructor(params: RouteParams) { this.name = params.get('name') || 'NOBODY'; }
|
constructor(params: RouteParams) { this.name = params.get('name') || 'NOBODY'; }
|
||||||
|
|
||||||
canReuse(next: ComponentInstruction, prev: ComponentInstruction) { return true; }
|
routerCanReuse(next: ComponentInstruction, prev: ComponentInstruction) { return true; }
|
||||||
|
|
||||||
onReuse(next: ComponentInstruction, prev: ComponentInstruction) {
|
routerOnReuse(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||||
this.name = next.params['name'];
|
this.name = next.params['name'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ export class NgClass implements DoCheck, OnDestroy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
doCheck(): void {
|
ngDoCheck(): void {
|
||||||
if (isPresent(this._differ)) {
|
if (isPresent(this._differ)) {
|
||||||
var changes = this._differ.diff(this._rawClass);
|
var changes = this._differ.diff(this._rawClass);
|
||||||
if (isPresent(changes)) {
|
if (isPresent(changes)) {
|
||||||
@ -121,7 +121,7 @@ export class NgClass implements DoCheck, OnDestroy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onDestroy(): void { this._cleanupClasses(this._rawClass); }
|
ngOnDestroy(): void { this._cleanupClasses(this._rawClass); }
|
||||||
|
|
||||||
private _cleanupClasses(rawClassVal): void {
|
private _cleanupClasses(rawClassVal): void {
|
||||||
this._applyClasses(rawClassVal, true);
|
this._applyClasses(rawClassVal, true);
|
||||||
|
@ -81,7 +81,7 @@ export class NgFor implements DoCheck {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
doCheck() {
|
ngDoCheck() {
|
||||||
if (isPresent(this._differ)) {
|
if (isPresent(this._differ)) {
|
||||||
var changes = this._differ.diff(this._ngForOf);
|
var changes = this._differ.diff(this._ngForOf);
|
||||||
if (isPresent(changes)) this._applyChanges(changes);
|
if (isPresent(changes)) this._applyChanges(changes);
|
||||||
|
@ -75,7 +75,7 @@ export class NgStyle implements DoCheck {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
doCheck() {
|
ngDoCheck() {
|
||||||
if (isPresent(this._differ)) {
|
if (isPresent(this._differ)) {
|
||||||
var changes = this._differ.diff(this._rawStyle);
|
var changes = this._differ.diff(this._rawStyle);
|
||||||
if (isPresent(changes)) {
|
if (isPresent(changes)) {
|
||||||
|
@ -87,9 +87,9 @@ export class NgControlGroup extends ControlContainer implements OnInit,
|
|||||||
this._parent = parent;
|
this._parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
onInit(): void { this.formDirective.addControlGroup(this); }
|
ngOnInit(): void { this.formDirective.addControlGroup(this); }
|
||||||
|
|
||||||
onDestroy(): void { this.formDirective.removeControlGroup(this); }
|
ngOnDestroy(): void { this.formDirective.removeControlGroup(this); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the {@link ControlGroup} backing this binding.
|
* Get the {@link ControlGroup} backing this binding.
|
||||||
|
@ -114,7 +114,7 @@ export class NgControlName extends NgControl implements OnChanges,
|
|||||||
this.valueAccessor = selectValueAccessor(this, valueAccessors);
|
this.valueAccessor = selectValueAccessor(this, valueAccessors);
|
||||||
}
|
}
|
||||||
|
|
||||||
onChanges(changes: {[key: string]: SimpleChange}) {
|
ngOnChanges(changes: {[key: string]: SimpleChange}) {
|
||||||
if (!this._added) {
|
if (!this._added) {
|
||||||
this.formDirective.addControl(this);
|
this.formDirective.addControl(this);
|
||||||
this._added = true;
|
this._added = true;
|
||||||
@ -125,7 +125,7 @@ export class NgControlName extends NgControl implements OnChanges,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onDestroy(): void { this.formDirective.removeControl(this); }
|
ngOnDestroy(): void { this.formDirective.removeControl(this); }
|
||||||
|
|
||||||
viewToModelUpdate(newValue: any): void {
|
viewToModelUpdate(newValue: any): void {
|
||||||
this.viewModel = newValue;
|
this.viewModel = newValue;
|
||||||
|
@ -97,7 +97,7 @@ export class NgFormControl extends NgControl implements OnChanges {
|
|||||||
this.valueAccessor = selectValueAccessor(this, valueAccessors);
|
this.valueAccessor = selectValueAccessor(this, valueAccessors);
|
||||||
}
|
}
|
||||||
|
|
||||||
onChanges(changes: {[key: string]: SimpleChange}): void {
|
ngOnChanges(changes: {[key: string]: SimpleChange}): void {
|
||||||
if (this._isControlChanged(changes)) {
|
if (this._isControlChanged(changes)) {
|
||||||
setUpControl(this.form, this);
|
setUpControl(this.form, this);
|
||||||
this.form.updateValueAndValidity({emitEvent: false});
|
this.form.updateValueAndValidity({emitEvent: false});
|
||||||
|
@ -113,7 +113,7 @@ export class NgFormModel extends ControlContainer implements Form,
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
onChanges(changes: {[key: string]: SimpleChange}): void {
|
ngOnChanges(changes: {[key: string]: SimpleChange}): void {
|
||||||
if (StringMapWrapper.contains(changes, "form")) {
|
if (StringMapWrapper.contains(changes, "form")) {
|
||||||
var sync = composeValidators(this._validators);
|
var sync = composeValidators(this._validators);
|
||||||
this.form.validator = Validators.compose([this.form.validator, sync]);
|
this.form.validator = Validators.compose([this.form.validator, sync]);
|
||||||
|
@ -71,7 +71,7 @@ export class NgModel extends NgControl implements OnChanges {
|
|||||||
this.valueAccessor = selectValueAccessor(this, valueAccessors);
|
this.valueAccessor = selectValueAccessor(this, valueAccessors);
|
||||||
}
|
}
|
||||||
|
|
||||||
onChanges(changes: {[key: string]: SimpleChange}) {
|
ngOnChanges(changes: {[key: string]: SimpleChange}) {
|
||||||
if (!this._added) {
|
if (!this._added) {
|
||||||
setUpControl(this._control, this);
|
setUpControl(this._control, this);
|
||||||
this._control.updateValueAndValidity({emitEvent: false});
|
this._control.updateValueAndValidity({emitEvent: false});
|
||||||
|
@ -473,19 +473,19 @@ export class ChangeDetectorJITGenerator {
|
|||||||
/** @internal */
|
/** @internal */
|
||||||
_genOnCheck(r: ProtoRecord): string {
|
_genOnCheck(r: ProtoRecord): string {
|
||||||
var br = r.bindingRecord;
|
var br = r.bindingRecord;
|
||||||
return `if (!throwOnChange) ${this._names.getDirectiveName(br.directiveRecord.directiveIndex)}.doCheck();`;
|
return `if (!throwOnChange) ${this._names.getDirectiveName(br.directiveRecord.directiveIndex)}.ngDoCheck();`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
_genOnInit(r: ProtoRecord): string {
|
_genOnInit(r: ProtoRecord): string {
|
||||||
var br = r.bindingRecord;
|
var br = r.bindingRecord;
|
||||||
return `if (!throwOnChange && ${this._names.getStateName()} === ${this.changeDetectorStateVarName}.NeverChecked) ${this._names.getDirectiveName(br.directiveRecord.directiveIndex)}.onInit();`;
|
return `if (!throwOnChange && ${this._names.getStateName()} === ${this.changeDetectorStateVarName}.NeverChecked) ${this._names.getDirectiveName(br.directiveRecord.directiveIndex)}.ngOnInit();`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
_genOnChange(r: ProtoRecord): string {
|
_genOnChange(r: ProtoRecord): string {
|
||||||
var br = r.bindingRecord;
|
var br = r.bindingRecord;
|
||||||
return `if (!throwOnChange && ${CHANGES_LOCAL}) ${this._names.getDirectiveName(br.directiveRecord.directiveIndex)}.onChanges(${CHANGES_LOCAL});`;
|
return `if (!throwOnChange && ${CHANGES_LOCAL}) ${this._names.getDirectiveName(br.directiveRecord.directiveIndex)}.ngOnChanges(${CHANGES_LOCAL});`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
|
@ -189,11 +189,11 @@ export class CodegenLogicUtil {
|
|||||||
var dir = directiveRecords[i];
|
var dir = directiveRecords[i];
|
||||||
if (dir.callAfterContentInit) {
|
if (dir.callAfterContentInit) {
|
||||||
res.push(
|
res.push(
|
||||||
`if(${this._names.getStateName()} ${eq} ${this._changeDetectorStateName}.NeverChecked) ${this._names.getDirectiveName(dir.directiveIndex)}.afterContentInit();`);
|
`if(${this._names.getStateName()} ${eq} ${this._changeDetectorStateName}.NeverChecked) ${this._names.getDirectiveName(dir.directiveIndex)}.ngAfterContentInit();`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dir.callAfterContentChecked) {
|
if (dir.callAfterContentChecked) {
|
||||||
res.push(`${this._names.getDirectiveName(dir.directiveIndex)}.afterContentChecked();`);
|
res.push(`${this._names.getDirectiveName(dir.directiveIndex)}.ngAfterContentChecked();`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
@ -207,11 +207,11 @@ export class CodegenLogicUtil {
|
|||||||
var dir = directiveRecords[i];
|
var dir = directiveRecords[i];
|
||||||
if (dir.callAfterViewInit) {
|
if (dir.callAfterViewInit) {
|
||||||
res.push(
|
res.push(
|
||||||
`if(${this._names.getStateName()} ${eq} ${this._changeDetectorStateName}.NeverChecked) ${this._names.getDirectiveName(dir.directiveIndex)}.afterViewInit();`);
|
`if(${this._names.getStateName()} ${eq} ${this._changeDetectorStateName}.NeverChecked) ${this._names.getDirectiveName(dir.directiveIndex)}.ngAfterViewInit();`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dir.callAfterViewChecked) {
|
if (dir.callAfterViewChecked) {
|
||||||
res.push(`${this._names.getDirectiveName(dir.directiveIndex)}.afterViewChecked();`);
|
res.push(`${this._names.getDirectiveName(dir.directiveIndex)}.ngAfterViewChecked();`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
@ -155,12 +155,12 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
|
|||||||
|
|
||||||
if (proto.isLifeCycleRecord()) {
|
if (proto.isLifeCycleRecord()) {
|
||||||
if (proto.name === "DoCheck" && !throwOnChange) {
|
if (proto.name === "DoCheck" && !throwOnChange) {
|
||||||
this._getDirectiveFor(directiveRecord.directiveIndex).doCheck();
|
this._getDirectiveFor(directiveRecord.directiveIndex).ngDoCheck();
|
||||||
} else if (proto.name === "OnInit" && !throwOnChange &&
|
} else if (proto.name === "OnInit" && !throwOnChange &&
|
||||||
this.state == ChangeDetectorState.NeverChecked) {
|
this.state == ChangeDetectorState.NeverChecked) {
|
||||||
this._getDirectiveFor(directiveRecord.directiveIndex).onInit();
|
this._getDirectiveFor(directiveRecord.directiveIndex).ngOnInit();
|
||||||
} else if (proto.name === "OnChanges" && isPresent(changes) && !throwOnChange) {
|
} else if (proto.name === "OnChanges" && isPresent(changes) && !throwOnChange) {
|
||||||
this._getDirectiveFor(directiveRecord.directiveIndex).onChanges(changes);
|
this._getDirectiveFor(directiveRecord.directiveIndex).ngOnChanges(changes);
|
||||||
}
|
}
|
||||||
} else if (proto.isSkipRecord()) {
|
} else if (proto.isSkipRecord()) {
|
||||||
protoIdx += this._computeSkipLength(protoIdx, proto, this.values);
|
protoIdx += this._computeSkipLength(protoIdx, proto, this.values);
|
||||||
@ -195,11 +195,11 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
|
|||||||
for (var i = dirs.length - 1; i >= 0; --i) {
|
for (var i = dirs.length - 1; i >= 0; --i) {
|
||||||
var dir = dirs[i];
|
var dir = dirs[i];
|
||||||
if (dir.callAfterContentInit && this.state == ChangeDetectorState.NeverChecked) {
|
if (dir.callAfterContentInit && this.state == ChangeDetectorState.NeverChecked) {
|
||||||
this._getDirectiveFor(dir.directiveIndex).afterContentInit();
|
this._getDirectiveFor(dir.directiveIndex).ngAfterContentInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dir.callAfterContentChecked) {
|
if (dir.callAfterContentChecked) {
|
||||||
this._getDirectiveFor(dir.directiveIndex).afterContentChecked();
|
this._getDirectiveFor(dir.directiveIndex).ngAfterContentChecked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -209,10 +209,10 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
|
|||||||
for (var i = dirs.length - 1; i >= 0; --i) {
|
for (var i = dirs.length - 1; i >= 0; --i) {
|
||||||
var dir = dirs[i];
|
var dir = dirs[i];
|
||||||
if (dir.callAfterViewInit && this.state == ChangeDetectorState.NeverChecked) {
|
if (dir.callAfterViewInit && this.state == ChangeDetectorState.NeverChecked) {
|
||||||
this._getDirectiveFor(dir.directiveIndex).afterViewInit();
|
this._getDirectiveFor(dir.directiveIndex).ngAfterViewInit();
|
||||||
}
|
}
|
||||||
if (dir.callAfterViewChecked) {
|
if (dir.callAfterViewChecked) {
|
||||||
this._getDirectiveFor(dir.directiveIndex).afterViewChecked();
|
this._getDirectiveFor(dir.directiveIndex).ngAfterViewChecked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,21 +8,21 @@ export function hasLifecycleHook(lcInterface: LifecycleHooks, token): boolean {
|
|||||||
|
|
||||||
switch (lcInterface) {
|
switch (lcInterface) {
|
||||||
case LifecycleHooks.AfterContentInit:
|
case LifecycleHooks.AfterContentInit:
|
||||||
return !!proto.afterContentInit;
|
return !!proto.ngAfterContentInit;
|
||||||
case LifecycleHooks.AfterContentChecked:
|
case LifecycleHooks.AfterContentChecked:
|
||||||
return !!proto.afterContentChecked;
|
return !!proto.ngAfterContentChecked;
|
||||||
case LifecycleHooks.AfterViewInit:
|
case LifecycleHooks.AfterViewInit:
|
||||||
return !!proto.afterViewInit;
|
return !!proto.ngAfterViewInit;
|
||||||
case LifecycleHooks.AfterViewChecked:
|
case LifecycleHooks.AfterViewChecked:
|
||||||
return !!proto.afterViewChecked;
|
return !!proto.ngAfterViewChecked;
|
||||||
case LifecycleHooks.OnChanges:
|
case LifecycleHooks.OnChanges:
|
||||||
return !!proto.onChanges;
|
return !!proto.ngOnChanges;
|
||||||
case LifecycleHooks.DoCheck:
|
case LifecycleHooks.DoCheck:
|
||||||
return !!proto.doCheck;
|
return !!proto.ngDoCheck;
|
||||||
case LifecycleHooks.OnDestroy:
|
case LifecycleHooks.OnDestroy:
|
||||||
return !!proto.onDestroy;
|
return !!proto.ngOnDestroy;
|
||||||
case LifecycleHooks.OnInit:
|
case LifecycleHooks.OnInit:
|
||||||
return !!proto.onInit;
|
return !!proto.ngOnInit;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,7 @@ import {QueryList} from './query_list';
|
|||||||
import {reflector} from 'angular2/src/core/reflection/reflection';
|
import {reflector} from 'angular2/src/core/reflection/reflection';
|
||||||
import {SetterFn} from 'angular2/src/core/reflection/types';
|
import {SetterFn} from 'angular2/src/core/reflection/types';
|
||||||
import {EventConfig} from 'angular2/src/core/linker/event_config';
|
import {EventConfig} from 'angular2/src/core/linker/event_config';
|
||||||
|
import {AfterViewChecked} from 'angular2/src/core/linker/interfaces';
|
||||||
import {PipeProvider} from 'angular2/src/core/pipes/pipe_provider';
|
import {PipeProvider} from 'angular2/src/core/pipes/pipe_provider';
|
||||||
|
|
||||||
import {LifecycleHooks} from './interfaces';
|
import {LifecycleHooks} from './interfaces';
|
||||||
@ -326,7 +327,8 @@ class _Context {
|
|||||||
constructor(public element: any, public componentElement: any, public injector: any) {}
|
constructor(public element: any, public componentElement: any, public injector: any) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ElementInjector extends TreeNode<ElementInjector> implements DependencyProvider {
|
export class ElementInjector extends TreeNode<ElementInjector> implements DependencyProvider,
|
||||||
|
AfterViewChecked {
|
||||||
private _host: ElementInjector;
|
private _host: ElementInjector;
|
||||||
private _preBuiltObjects: PreBuiltObjects = null;
|
private _preBuiltObjects: PreBuiltObjects = null;
|
||||||
private _queryStrategy: _QueryStrategy;
|
private _queryStrategy: _QueryStrategy;
|
||||||
@ -564,9 +566,9 @@ export class ElementInjector extends TreeNode<ElementInjector> implements Depend
|
|||||||
return isPresent(nestedView) ? nestedView.rootElementInjectors : [];
|
return isPresent(nestedView) ? nestedView.rootElementInjectors : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
afterViewChecked(): void { this._queryStrategy.updateViewQueries(); }
|
ngAfterViewChecked(): void { this._queryStrategy.updateViewQueries(); }
|
||||||
|
|
||||||
afterContentChecked(): void { this._queryStrategy.updateContentQueries(); }
|
ngAfterContentChecked(): void { this._queryStrategy.updateContentQueries(); }
|
||||||
|
|
||||||
traverseAndSetQueriesAsDirty(): void {
|
traverseAndSetQueriesAsDirty(): void {
|
||||||
var inj = this;
|
var inj = this;
|
||||||
@ -810,43 +812,43 @@ class ElementInjectorInlineStrategy implements _ElementInjectorStrategy {
|
|||||||
|
|
||||||
if (p.provider0 instanceof DirectiveProvider &&
|
if (p.provider0 instanceof DirectiveProvider &&
|
||||||
(<DirectiveProvider>p.provider0).callOnDestroy) {
|
(<DirectiveProvider>p.provider0).callOnDestroy) {
|
||||||
i.obj0.onDestroy();
|
i.obj0.ngOnDestroy();
|
||||||
}
|
}
|
||||||
if (p.provider1 instanceof DirectiveProvider &&
|
if (p.provider1 instanceof DirectiveProvider &&
|
||||||
(<DirectiveProvider>p.provider1).callOnDestroy) {
|
(<DirectiveProvider>p.provider1).callOnDestroy) {
|
||||||
i.obj1.onDestroy();
|
i.obj1.ngOnDestroy();
|
||||||
}
|
}
|
||||||
if (p.provider2 instanceof DirectiveProvider &&
|
if (p.provider2 instanceof DirectiveProvider &&
|
||||||
(<DirectiveProvider>p.provider2).callOnDestroy) {
|
(<DirectiveProvider>p.provider2).callOnDestroy) {
|
||||||
i.obj2.onDestroy();
|
i.obj2.ngOnDestroy();
|
||||||
}
|
}
|
||||||
if (p.provider3 instanceof DirectiveProvider &&
|
if (p.provider3 instanceof DirectiveProvider &&
|
||||||
(<DirectiveProvider>p.provider3).callOnDestroy) {
|
(<DirectiveProvider>p.provider3).callOnDestroy) {
|
||||||
i.obj3.onDestroy();
|
i.obj3.ngOnDestroy();
|
||||||
}
|
}
|
||||||
if (p.provider4 instanceof DirectiveProvider &&
|
if (p.provider4 instanceof DirectiveProvider &&
|
||||||
(<DirectiveProvider>p.provider4).callOnDestroy) {
|
(<DirectiveProvider>p.provider4).callOnDestroy) {
|
||||||
i.obj4.onDestroy();
|
i.obj4.ngOnDestroy();
|
||||||
}
|
}
|
||||||
if (p.provider5 instanceof DirectiveProvider &&
|
if (p.provider5 instanceof DirectiveProvider &&
|
||||||
(<DirectiveProvider>p.provider5).callOnDestroy) {
|
(<DirectiveProvider>p.provider5).callOnDestroy) {
|
||||||
i.obj5.onDestroy();
|
i.obj5.ngOnDestroy();
|
||||||
}
|
}
|
||||||
if (p.provider6 instanceof DirectiveProvider &&
|
if (p.provider6 instanceof DirectiveProvider &&
|
||||||
(<DirectiveProvider>p.provider6).callOnDestroy) {
|
(<DirectiveProvider>p.provider6).callOnDestroy) {
|
||||||
i.obj6.onDestroy();
|
i.obj6.ngOnDestroy();
|
||||||
}
|
}
|
||||||
if (p.provider7 instanceof DirectiveProvider &&
|
if (p.provider7 instanceof DirectiveProvider &&
|
||||||
(<DirectiveProvider>p.provider7).callOnDestroy) {
|
(<DirectiveProvider>p.provider7).callOnDestroy) {
|
||||||
i.obj7.onDestroy();
|
i.obj7.ngOnDestroy();
|
||||||
}
|
}
|
||||||
if (p.provider8 instanceof DirectiveProvider &&
|
if (p.provider8 instanceof DirectiveProvider &&
|
||||||
(<DirectiveProvider>p.provider8).callOnDestroy) {
|
(<DirectiveProvider>p.provider8).callOnDestroy) {
|
||||||
i.obj8.onDestroy();
|
i.obj8.ngOnDestroy();
|
||||||
}
|
}
|
||||||
if (p.provider9 instanceof DirectiveProvider &&
|
if (p.provider9 instanceof DirectiveProvider &&
|
||||||
(<DirectiveProvider>p.provider9).callOnDestroy) {
|
(<DirectiveProvider>p.provider9).callOnDestroy) {
|
||||||
i.obj9.onDestroy();
|
i.obj9.ngOnDestroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -936,7 +938,7 @@ class ElementInjectorDynamicStrategy implements _ElementInjectorStrategy {
|
|||||||
for (var i = 0; i < p.providers.length; i++) {
|
for (var i = 0; i < p.providers.length; i++) {
|
||||||
if (p.providers[i] instanceof DirectiveProvider &&
|
if (p.providers[i] instanceof DirectiveProvider &&
|
||||||
(<DirectiveProvider>p.providers[i]).callOnDestroy) {
|
(<DirectiveProvider>p.providers[i]).callOnDestroy) {
|
||||||
ist.objs[i].onDestroy();
|
ist.objs[i].ngOnDestroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ export var LIFECYCLE_HOOKS_VALUES = [
|
|||||||
/**
|
/**
|
||||||
* Implement this interface to get notified when any data-bound property of your directive changes.
|
* Implement this interface to get notified when any data-bound property of your directive changes.
|
||||||
*
|
*
|
||||||
* `onChanges` is called right after the data-bound properties have been checked and before view
|
* `ngOnChanges` is called right after the data-bound properties have been checked and before view
|
||||||
* and content children are checked if at least one of them has changed.
|
* and content children are checked if at least one of them has changed.
|
||||||
*
|
*
|
||||||
* The `changes` parameter contains an entry for each of the changed data-bound property. The key is
|
* The `changes` parameter contains an entry for each of the changed data-bound property. The key is
|
||||||
@ -57,8 +57,8 @@ export var LIFECYCLE_HOOKS_VALUES = [
|
|||||||
* class MyComponent implements OnChanges {
|
* class MyComponent implements OnChanges {
|
||||||
* @Input() myProp: any;
|
* @Input() myProp: any;
|
||||||
*
|
*
|
||||||
* onChanges(changes: {[propName: string]: SimpleChange}) {
|
* ngOnChanges(changes: {[propName: string]: SimpleChange}) {
|
||||||
* console.log('onChanges - myProp = ' + changes['myProp'].currentValue);
|
* console.log('ngOnChanges - myProp = ' + changes['myProp'].currentValue);
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
@ -76,13 +76,13 @@ export var LIFECYCLE_HOOKS_VALUES = [
|
|||||||
* bootstrap(App).catch(err => console.error(err));
|
* bootstrap(App).catch(err => console.error(err));
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export interface OnChanges { onChanges(changes: {[key: string]: SimpleChange}); }
|
export interface OnChanges { ngOnChanges(changes: {[key: string]: SimpleChange}); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implement this interface to execute custom initialization logic after your directive's
|
* Implement this interface to execute custom initialization logic after your directive's
|
||||||
* data-bound properties have been initialized.
|
* data-bound properties have been initialized.
|
||||||
*
|
*
|
||||||
* `onInit` is called right after the directive's data-bound properties have been checked for the
|
* `ngOnInit` is called right after the directive's data-bound properties have been checked for the
|
||||||
* first time, and before any of its children have been checked. It is invoked only once when the
|
* first time, and before any of its children have been checked. It is invoked only once when the
|
||||||
* directive is instantiated.
|
* directive is instantiated.
|
||||||
*
|
*
|
||||||
@ -94,12 +94,12 @@ export interface OnChanges { onChanges(changes: {[key: string]: SimpleChange});
|
|||||||
* template: `<p>my-component</p>`
|
* template: `<p>my-component</p>`
|
||||||
* })
|
* })
|
||||||
* class MyComponent implements OnInit, OnDestroy {
|
* class MyComponent implements OnInit, OnDestroy {
|
||||||
* onInit() {
|
* ngOnInit() {
|
||||||
* console.log('onInit');
|
* console.log('ngOnInit');
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* onDestroy() {
|
* ngOnDestroy() {
|
||||||
* console.log('onDestroy');
|
* console.log('ngOnDestroy');
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
@ -119,29 +119,29 @@ export interface OnChanges { onChanges(changes: {[key: string]: SimpleChange});
|
|||||||
* bootstrap(App).catch(err => console.error(err));
|
* bootstrap(App).catch(err => console.error(err));
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export interface OnInit { onInit(); }
|
export interface OnInit { ngOnInit(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implement this interface to override the default change detection algorithm for your directive.
|
* Implement this interface to override the default change detection algorithm for your directive.
|
||||||
*
|
*
|
||||||
* `doCheck` gets called to check the changes in the directives instead of the default algorithm.
|
* `ngDoCheck` gets called to check the changes in the directives instead of the default algorithm.
|
||||||
*
|
*
|
||||||
* The default change detection algorithm looks for differences by comparing bound-property values
|
* The default change detection algorithm looks for differences by comparing bound-property values
|
||||||
* by reference across change detection runs. When `DoCheck` is implemented, the default algorithm
|
* by reference across change detection runs. When `DoCheck` is implemented, the default algorithm
|
||||||
* is disabled and `doCheck` is responsible for checking for changes.
|
* is disabled and `ngDoCheck` is responsible for checking for changes.
|
||||||
*
|
*
|
||||||
* Implementing this interface allows improving performance by using insights about the component,
|
* Implementing this interface allows improving performance by using insights about the component,
|
||||||
* its implementation and data types of its properties.
|
* its implementation and data types of its properties.
|
||||||
*
|
*
|
||||||
* Note that a directive should not implement both `DoCheck` and {@link OnChanges} at the same time.
|
* Note that a directive should not implement both `DoCheck` and {@link OnChanges} at the same time.
|
||||||
* `onChanges` would not be called when a directive implements `DoCheck`. Reaction to the changes
|
* `ngOnChanges` would not be called when a directive implements `DoCheck`. Reaction to the changes
|
||||||
* have to be handled from within the `doCheck` callback.
|
* have to be handled from within the `ngDoCheck` callback.
|
||||||
*
|
*
|
||||||
* Use {@link KeyValueDiffers} and {@link IterableDiffers} to add your custom check mechanisms.
|
* Use {@link KeyValueDiffers} and {@link IterableDiffers} to add your custom check mechanisms.
|
||||||
*
|
*
|
||||||
* ### Example ([live demo](http://plnkr.co/edit/QpnIlF0CR2i5bcYbHEUJ?p=preview))
|
* ### Example ([live demo](http://plnkr.co/edit/QpnIlF0CR2i5bcYbHEUJ?p=preview))
|
||||||
*
|
*
|
||||||
* In the following example `doCheck` uses an {@link IterableDiffers} to detect the updates to the
|
* In the following example `ngDoCheck` uses an {@link IterableDiffers} to detect the updates to the
|
||||||
* array `list`:
|
* array `list`:
|
||||||
*
|
*
|
||||||
* ```typescript
|
* ```typescript
|
||||||
@ -163,7 +163,7 @@ export interface OnInit { onInit(); }
|
|||||||
* this.differ = differs.find([]).create(null);
|
* this.differ = differs.find([]).create(null);
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* doCheck() {
|
* ngDoCheck() {
|
||||||
* var changes = this.differ.diff(this.list);
|
* var changes = this.differ.diff(this.list);
|
||||||
*
|
*
|
||||||
* if (changes) {
|
* if (changes) {
|
||||||
@ -186,12 +186,12 @@ export interface OnInit { onInit(); }
|
|||||||
* }
|
* }
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export interface DoCheck { doCheck(); }
|
export interface DoCheck { ngDoCheck(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implement this interface to get notified when your directive is destroyed.
|
* Implement this interface to get notified when your directive is destroyed.
|
||||||
*
|
*
|
||||||
* `onDestroy` callback is typically used for any custom cleanup that needs to occur when the
|
* `ngOnDestroy` callback is typically used for any custom cleanup that needs to occur when the
|
||||||
* instance is destroyed
|
* instance is destroyed
|
||||||
*
|
*
|
||||||
* ### Example ([live example](http://plnkr.co/edit/1MBypRryXd64v4pV03Yn?p=preview))
|
* ### Example ([live example](http://plnkr.co/edit/1MBypRryXd64v4pV03Yn?p=preview))
|
||||||
@ -202,12 +202,12 @@ export interface DoCheck { doCheck(); }
|
|||||||
* template: `<p>my-component</p>`
|
* template: `<p>my-component</p>`
|
||||||
* })
|
* })
|
||||||
* class MyComponent implements OnInit, OnDestroy {
|
* class MyComponent implements OnInit, OnDestroy {
|
||||||
* onInit() {
|
* ngOnInit() {
|
||||||
* console.log('onInit');
|
* console.log('ngOnInit');
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* onDestroy() {
|
* ngOnDestroy() {
|
||||||
* console.log('onDestroy');
|
* console.log('ngOnDestroy');
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
@ -227,7 +227,7 @@ export interface DoCheck { doCheck(); }
|
|||||||
* bootstrap(App).catch(err => console.error(err));
|
* bootstrap(App).catch(err => console.error(err));
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export interface OnDestroy { onDestroy(); }
|
export interface OnDestroy { ngOnDestroy(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implement this interface to get notified when your directive's content has been fully
|
* Implement this interface to get notified when your directive's content has been fully
|
||||||
@ -256,7 +256,7 @@ export interface OnDestroy { onDestroy(); }
|
|||||||
* console.log(this.getMessage(this.contentChild));
|
* console.log(this.getMessage(this.contentChild));
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* afterContentInit() {
|
* ngAfterContentInit() {
|
||||||
* // contentChild is updated after the content has been checked
|
* // contentChild is updated after the content has been checked
|
||||||
* console.log('AfterContentInit: ' + this.getMessage(this.contentChild));
|
* console.log('AfterContentInit: ' + this.getMessage(this.contentChild));
|
||||||
* }
|
* }
|
||||||
@ -280,7 +280,7 @@ export interface OnDestroy { onDestroy(); }
|
|||||||
* bootstrap(App).catch(err => console.error(err));
|
* bootstrap(App).catch(err => console.error(err));
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export interface AfterContentInit { afterContentInit(); }
|
export interface AfterContentInit { ngAfterContentInit(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implement this interface to get notified after every check of your directive's content.
|
* Implement this interface to get notified after every check of your directive's content.
|
||||||
@ -302,7 +302,7 @@ export interface AfterContentInit { afterContentInit(); }
|
|||||||
* console.log(this.getMessage(this.contentChild));
|
* console.log(this.getMessage(this.contentChild));
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* afterContentChecked() {
|
* ngAfterContentChecked() {
|
||||||
* // contentChild is updated after the content has been checked
|
* // contentChild is updated after the content has been checked
|
||||||
* console.log('AfterContentChecked: ' + this.getMessage(this.contentChild));
|
* console.log('AfterContentChecked: ' + this.getMessage(this.contentChild));
|
||||||
* }
|
* }
|
||||||
@ -328,7 +328,7 @@ export interface AfterContentInit { afterContentInit(); }
|
|||||||
* bootstrap(App).catch(err => console.error(err));
|
* bootstrap(App).catch(err => console.error(err));
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export interface AfterContentChecked { afterContentChecked(); }
|
export interface AfterContentChecked { ngAfterContentChecked(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implement this interface to get notified when your component's view has been fully initialized.
|
* Implement this interface to get notified when your component's view has been fully initialized.
|
||||||
@ -354,9 +354,9 @@ export interface AfterContentChecked { afterContentChecked(); }
|
|||||||
* console.log(this.getMessage(this.viewChild));
|
* console.log(this.getMessage(this.viewChild));
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* afterViewInit() {
|
* ngAfterViewInit() {
|
||||||
* // viewChild is updated after the view has been initialized
|
* // viewChild is updated after the view has been initialized
|
||||||
* console.log('afterViewInit: ' + this.getMessage(this.viewChild));
|
* console.log('ngAfterViewInit: ' + this.getMessage(this.viewChild));
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* private getMessage(cmp: ChildComponent): string {
|
* private getMessage(cmp: ChildComponent): string {
|
||||||
@ -375,7 +375,7 @@ export interface AfterContentChecked { afterContentChecked(); }
|
|||||||
* bootstrap(App).catch(err => console.error(err));
|
* bootstrap(App).catch(err => console.error(err));
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export interface AfterViewInit { afterViewInit(); }
|
export interface AfterViewInit { ngAfterViewInit(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implement this interface to get notified after every check of your component's view.
|
* Implement this interface to get notified after every check of your component's view.
|
||||||
@ -404,7 +404,7 @@ export interface AfterViewInit { afterViewInit(); }
|
|||||||
* console.log(this.getMessage(this.viewChild));
|
* console.log(this.getMessage(this.viewChild));
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* afterViewChecked() {
|
* ngAfterViewChecked() {
|
||||||
* // viewChild is updated after the view has been checked
|
* // viewChild is updated after the view has been checked
|
||||||
* console.log('AfterViewChecked: ' + this.getMessage(this.viewChild));
|
* console.log('AfterViewChecked: ' + this.getMessage(this.viewChild));
|
||||||
* }
|
* }
|
||||||
@ -425,4 +425,4 @@ export interface AfterViewInit { afterViewInit(); }
|
|||||||
* bootstrap(App).catch(err => console.error(err));
|
* bootstrap(App).catch(err => console.error(err));
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export interface AfterViewChecked { afterViewChecked(); }
|
export interface AfterViewChecked { ngAfterViewChecked(); }
|
||||||
|
@ -182,7 +182,7 @@ export class AppView implements ChangeDispatcher, RenderEventDispatcher {
|
|||||||
var eiCount = this.proto.elementBinders.length;
|
var eiCount = this.proto.elementBinders.length;
|
||||||
var ei = this.elementInjectors;
|
var ei = this.elementInjectors;
|
||||||
for (var i = eiCount - 1; i >= 0; i--) {
|
for (var i = eiCount - 1; i >= 0; i--) {
|
||||||
if (isPresent(ei[i + this.elementOffset])) ei[i + this.elementOffset].afterContentChecked();
|
if (isPresent(ei[i + this.elementOffset])) ei[i + this.elementOffset].ngAfterContentChecked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ export class AppView implements ChangeDispatcher, RenderEventDispatcher {
|
|||||||
var eiCount = this.proto.elementBinders.length;
|
var eiCount = this.proto.elementBinders.length;
|
||||||
var ei = this.elementInjectors;
|
var ei = this.elementInjectors;
|
||||||
for (var i = eiCount - 1; i >= 0; i--) {
|
for (var i = eiCount - 1; i >= 0; i--) {
|
||||||
if (isPresent(ei[i + this.elementOffset])) ei[i + this.elementOffset].afterViewChecked();
|
if (isPresent(ei[i + this.elementOffset])) ei[i + this.elementOffset].ngAfterViewChecked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ export abstract class AppViewManager {
|
|||||||
* Parent (<some-component></some-component>)
|
* Parent (<some-component></some-component>)
|
||||||
* `
|
* `
|
||||||
* })
|
* })
|
||||||
* class MyApp {
|
* class MyApp implements OnDestroy {
|
||||||
* viewRef: ng.ViewRef;
|
* viewRef: ng.ViewRef;
|
||||||
*
|
*
|
||||||
* constructor(public appViewManager: ng.AppViewManager, compiler: ng.Compiler) {
|
* constructor(public appViewManager: ng.AppViewManager, compiler: ng.Compiler) {
|
||||||
@ -106,7 +106,7 @@ export abstract class AppViewManager {
|
|||||||
* })
|
* })
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* onDestroy() {
|
* ngOnDestroy() {
|
||||||
* this.appViewManager.destroyRootHostView(this.viewRef);
|
* this.appViewManager.destroyRootHostView(this.viewRef);
|
||||||
* this.viewRef = null;
|
* this.viewRef = null;
|
||||||
* }
|
* }
|
||||||
|
@ -1108,7 +1108,7 @@ export var Query: QueryFactory = makeParamDecorator(QueryMetadata);
|
|||||||
/**
|
/**
|
||||||
* Configures a content query.
|
* Configures a content query.
|
||||||
*
|
*
|
||||||
* Content queries are set before the `afterContentInit` callback is called.
|
* Content queries are set before the `ngAfterContentInit` callback is called.
|
||||||
*
|
*
|
||||||
* ### Example
|
* ### Example
|
||||||
*
|
*
|
||||||
@ -1119,7 +1119,7 @@ export var Query: QueryFactory = makeParamDecorator(QueryMetadata);
|
|||||||
* class SomeDir {
|
* class SomeDir {
|
||||||
* @ContentChildren(ChildDirective) contentChildren: QueryList<ChildDirective>;
|
* @ContentChildren(ChildDirective) contentChildren: QueryList<ChildDirective>;
|
||||||
*
|
*
|
||||||
* afterContentInit() {
|
* ngAfterContentInit() {
|
||||||
* // contentChildren is set
|
* // contentChildren is set
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
@ -1131,7 +1131,7 @@ export var ContentChildren: ContentChildrenFactory = makePropDecorator(ContentCh
|
|||||||
/**
|
/**
|
||||||
* Configures a content query.
|
* Configures a content query.
|
||||||
*
|
*
|
||||||
* Content queries are set before the `afterContentInit` callback is called.
|
* Content queries are set before the `ngAfterContentInit` callback is called.
|
||||||
*
|
*
|
||||||
* ### Example
|
* ### Example
|
||||||
*
|
*
|
||||||
@ -1142,7 +1142,7 @@ export var ContentChildren: ContentChildrenFactory = makePropDecorator(ContentCh
|
|||||||
* class SomeDir {
|
* class SomeDir {
|
||||||
* @ContentChild(ChildDirective) contentChild;
|
* @ContentChild(ChildDirective) contentChild;
|
||||||
*
|
*
|
||||||
* afterContentInit() {
|
* ngAfterContentInit() {
|
||||||
* // contentChild is set
|
* // contentChild is set
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
@ -1154,7 +1154,7 @@ export var ContentChild: ContentChildFactory = makePropDecorator(ContentChildMet
|
|||||||
/**
|
/**
|
||||||
* Configures a view query.
|
* Configures a view query.
|
||||||
*
|
*
|
||||||
* View queries are set before the `afterViewInit` callback is called.
|
* View queries are set before the `ngAfterViewInit` callback is called.
|
||||||
*
|
*
|
||||||
* ### Example
|
* ### Example
|
||||||
*
|
*
|
||||||
@ -1167,7 +1167,7 @@ export var ContentChild: ContentChildFactory = makePropDecorator(ContentChildMet
|
|||||||
* class SomeDir {
|
* class SomeDir {
|
||||||
* @ViewChildren(ItemDirective) viewChildren: QueryList<ItemDirective>;
|
* @ViewChildren(ItemDirective) viewChildren: QueryList<ItemDirective>;
|
||||||
*
|
*
|
||||||
* afterViewInit() {
|
* ngAfterViewInit() {
|
||||||
* // viewChildren is set
|
* // viewChildren is set
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
@ -1179,7 +1179,7 @@ export var ViewChildren: ViewChildrenFactory = makePropDecorator(ViewChildrenMet
|
|||||||
/**
|
/**
|
||||||
* Configures a view query.
|
* Configures a view query.
|
||||||
*
|
*
|
||||||
* View queries are set before the `afterViewInit` callback is called.
|
* View queries are set before the `ngAfterViewInit` callback is called.
|
||||||
*
|
*
|
||||||
* ### Example
|
* ### Example
|
||||||
*
|
*
|
||||||
@ -1192,7 +1192,7 @@ export var ViewChildren: ViewChildrenFactory = makePropDecorator(ViewChildrenMet
|
|||||||
* class SomeDir {
|
* class SomeDir {
|
||||||
* @ViewChild(ItemDirective) viewChild:ItemDirective;
|
* @ViewChild(ItemDirective) viewChild:ItemDirective;
|
||||||
*
|
*
|
||||||
* afterViewInit() {
|
* ngAfterViewInit() {
|
||||||
* // viewChild is set
|
* // viewChild is set
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
|
@ -194,7 +194,7 @@ export class QueryMetadata extends DependencyMetadata {
|
|||||||
/**
|
/**
|
||||||
* Configures a content query.
|
* Configures a content query.
|
||||||
*
|
*
|
||||||
* Content queries are set before the `afterContentInit` callback is called.
|
* Content queries are set before the `ngAfterContentInit` callback is called.
|
||||||
*
|
*
|
||||||
* ### Example
|
* ### Example
|
||||||
*
|
*
|
||||||
@ -205,7 +205,7 @@ export class QueryMetadata extends DependencyMetadata {
|
|||||||
* class SomeDir {
|
* class SomeDir {
|
||||||
* @ContentChildren(ChildDirective) contentChildren: QueryList<ChildDirective>;
|
* @ContentChildren(ChildDirective) contentChildren: QueryList<ChildDirective>;
|
||||||
*
|
*
|
||||||
* afterContentInit() {
|
* ngAfterContentInit() {
|
||||||
* // contentChildren is set
|
* // contentChildren is set
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
@ -222,7 +222,7 @@ export class ContentChildrenMetadata extends QueryMetadata {
|
|||||||
/**
|
/**
|
||||||
* Configures a content query.
|
* Configures a content query.
|
||||||
*
|
*
|
||||||
* Content queries are set before the `afterContentInit` callback is called.
|
* Content queries are set before the `ngAfterContentInit` callback is called.
|
||||||
*
|
*
|
||||||
* ### Example
|
* ### Example
|
||||||
*
|
*
|
||||||
@ -233,7 +233,7 @@ export class ContentChildrenMetadata extends QueryMetadata {
|
|||||||
* class SomeDir {
|
* class SomeDir {
|
||||||
* @ContentChild(ChildDirective) contentChild;
|
* @ContentChild(ChildDirective) contentChild;
|
||||||
*
|
*
|
||||||
* afterContentInit() {
|
* ngAfterContentInit() {
|
||||||
* // contentChild is set
|
* // contentChild is set
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
@ -296,7 +296,7 @@ export class ViewQueryMetadata extends QueryMetadata {
|
|||||||
/**
|
/**
|
||||||
* Configures a view query.
|
* Configures a view query.
|
||||||
*
|
*
|
||||||
* View queries are set before the `afterViewInit` callback is called.
|
* View queries are set before the `ngAfterViewInit` callback is called.
|
||||||
*
|
*
|
||||||
* ### Example
|
* ### Example
|
||||||
*
|
*
|
||||||
@ -309,7 +309,7 @@ export class ViewQueryMetadata extends QueryMetadata {
|
|||||||
* class SomeDir {
|
* class SomeDir {
|
||||||
* @ViewChildren(ItemDirective) viewChildren: QueryList<ItemDirective>;
|
* @ViewChildren(ItemDirective) viewChildren: QueryList<ItemDirective>;
|
||||||
*
|
*
|
||||||
* afterViewInit() {
|
* ngAfterViewInit() {
|
||||||
* // viewChildren is set
|
* // viewChildren is set
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
@ -323,7 +323,7 @@ export class ViewChildrenMetadata extends ViewQueryMetadata {
|
|||||||
/**
|
/**
|
||||||
* Configures a view query.
|
* Configures a view query.
|
||||||
*
|
*
|
||||||
* View queries are set before the `afterViewInit` callback is called.
|
* View queries are set before the `ngAfterViewInit` callback is called.
|
||||||
*
|
*
|
||||||
* ### Example
|
* ### Example
|
||||||
*
|
*
|
||||||
@ -336,7 +336,7 @@ export class ViewChildrenMetadata extends ViewQueryMetadata {
|
|||||||
* class SomeDir {
|
* class SomeDir {
|
||||||
* @ViewChild(ItemDirective) viewChild:ItemDirective;
|
* @ViewChild(ItemDirective) viewChild:ItemDirective;
|
||||||
*
|
*
|
||||||
* afterViewInit() {
|
* ngAfterViewInit() {
|
||||||
* // viewChild is set
|
* // viewChild is set
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
|
@ -720,8 +720,8 @@ export class DirectiveMetadata extends InjectableMetadata {
|
|||||||
/**
|
/**
|
||||||
* Configures the queries that will be injected into the directive.
|
* Configures the queries that will be injected into the directive.
|
||||||
*
|
*
|
||||||
* Content queries are set before the `afterContentInit` callback is called.
|
* Content queries are set before the `ngAfterContentInit` callback is called.
|
||||||
* View queries are set before the `afterViewInit` callback is called.
|
* View queries are set before the `ngAfterViewInit` callback is called.
|
||||||
*
|
*
|
||||||
* ### Example
|
* ### Example
|
||||||
*
|
*
|
||||||
@ -739,11 +739,11 @@ export class DirectiveMetadata extends InjectableMetadata {
|
|||||||
* contentChildren: QueryList<ChildDirective>,
|
* contentChildren: QueryList<ChildDirective>,
|
||||||
* viewChildren: QueryList<ChildDirective>
|
* viewChildren: QueryList<ChildDirective>
|
||||||
*
|
*
|
||||||
* afterContentInit() {
|
* ngAfterContentInit() {
|
||||||
* // contentChildren is set
|
* // contentChildren is set
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* afterViewInit() {
|
* ngAfterViewInit() {
|
||||||
* // viewChildren is set
|
* // viewChildren is set
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
|
@ -8,34 +8,37 @@ var __ignore_me = global;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines route lifecycle method `onActivate`, which is called by the router at the end of a
|
* Defines route lifecycle method `routerOnActivate`, which is called by the router at the end of a
|
||||||
* successful route navigation.
|
* successful route navigation.
|
||||||
*
|
*
|
||||||
* For a single component's navigation, only one of either {@link OnActivate} or {@link OnReuse}
|
* For a single component's navigation, only one of either {@link OnActivate} or {@link OnReuse}
|
||||||
* will be called depending on the result of {@link CanReuse}.
|
* will be called depending on the result of {@link CanReuse}.
|
||||||
*
|
*
|
||||||
* The `onActivate` hook is called with two {@link ComponentInstruction}s as parameters, the first
|
* The `routerOnActivate` hook is called with two {@link ComponentInstruction}s as parameters, the
|
||||||
|
* first
|
||||||
* representing the current route being navigated to, and the second parameter representing the
|
* representing the current route being navigated to, and the second parameter representing the
|
||||||
* previous route or `null`.
|
* previous route or `null`.
|
||||||
*
|
*
|
||||||
* If `onActivate` returns a promise, the route change will wait until the promise settles to
|
* If `routerOnActivate` returns a promise, the route change will wait until the promise settles to
|
||||||
* instantiate and activate child components.
|
* instantiate and activate child components.
|
||||||
*
|
*
|
||||||
* ### Example
|
* ### Example
|
||||||
* {@example router/ts/on_activate/on_activate_example.ts region='onActivate'}
|
* {@example router/ts/on_activate/on_activate_example.ts region='routerOnActivate'}
|
||||||
*/
|
*/
|
||||||
export interface OnActivate {
|
export interface OnActivate {
|
||||||
onActivate(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction): any;
|
routerOnActivate(nextInstruction: ComponentInstruction,
|
||||||
|
prevInstruction: ComponentInstruction): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines route lifecycle method `onReuse`, which is called by the router at the end of a
|
* Defines route lifecycle method `routerOnReuse`, which is called by the router at the end of a
|
||||||
* successful route navigation when {@link CanReuse} is implemented and returns or resolves to true.
|
* successful route navigation when {@link CanReuse} is implemented and returns or resolves to true.
|
||||||
*
|
*
|
||||||
* For a single component's navigation, only one of either {@link OnActivate} or {@link OnReuse}
|
* For a single component's navigation, only one of either {@link OnActivate} or {@link OnReuse}
|
||||||
* will be called, depending on the result of {@link CanReuse}.
|
* will be called, depending on the result of {@link CanReuse}.
|
||||||
*
|
*
|
||||||
* The `onReuse` hook is called with two {@link ComponentInstruction}s as parameters, the first
|
* The `routerOnReuse` hook is called with two {@link ComponentInstruction}s as parameters, the
|
||||||
|
* first
|
||||||
* representing the current route being navigated to, and the second parameter representing the
|
* representing the current route being navigated to, and the second parameter representing the
|
||||||
* previous route or `null`.
|
* previous route or `null`.
|
||||||
*
|
*
|
||||||
@ -43,65 +46,73 @@ export interface OnActivate {
|
|||||||
* {@example router/ts/reuse/reuse_example.ts region='reuseCmp'}
|
* {@example router/ts/reuse/reuse_example.ts region='reuseCmp'}
|
||||||
*/
|
*/
|
||||||
export interface OnReuse {
|
export interface OnReuse {
|
||||||
onReuse(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction): any;
|
routerOnReuse(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines route lifecycle method `onDeactivate`, which is called by the router before destroying
|
* Defines route lifecycle method `routerOnDeactivate`, which is called by the router before
|
||||||
|
* destroying
|
||||||
* a component as part of a route change.
|
* a component as part of a route change.
|
||||||
*
|
*
|
||||||
* The `onDeactivate` hook is called with two {@link ComponentInstruction}s as parameters, the first
|
* The `routerOnDeactivate` hook is called with two {@link ComponentInstruction}s as parameters, the
|
||||||
|
* first
|
||||||
* representing the current route being navigated to, and the second parameter representing the
|
* representing the current route being navigated to, and the second parameter representing the
|
||||||
* previous route.
|
* previous route.
|
||||||
*
|
*
|
||||||
* If `onDeactivate` returns a promise, the route change will wait until the promise settles.
|
* If `routerOnDeactivate` returns a promise, the route change will wait until the promise settles.
|
||||||
*
|
*
|
||||||
* ### Example
|
* ### Example
|
||||||
* {@example router/ts/on_deactivate/on_deactivate_example.ts region='onDeactivate'}
|
* {@example router/ts/on_deactivate/on_deactivate_example.ts region='routerOnDeactivate'}
|
||||||
*/
|
*/
|
||||||
export interface OnDeactivate {
|
export interface OnDeactivate {
|
||||||
onDeactivate(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction): any;
|
routerOnDeactivate(nextInstruction: ComponentInstruction,
|
||||||
|
prevInstruction: ComponentInstruction): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines route lifecycle method `canReuse`, which is called by the router to determine whether a
|
* Defines route lifecycle method `routerCanReuse`, which is called by the router to determine
|
||||||
|
* whether a
|
||||||
* component should be reused across routes, or whether to destroy and instantiate a new component.
|
* component should be reused across routes, or whether to destroy and instantiate a new component.
|
||||||
*
|
*
|
||||||
* The `canReuse` hook is called with two {@link ComponentInstruction}s as parameters, the first
|
* The `routerCanReuse` hook is called with two {@link ComponentInstruction}s as parameters, the
|
||||||
|
* first
|
||||||
* representing the current route being navigated to, and the second parameter representing the
|
* representing the current route being navigated to, and the second parameter representing the
|
||||||
* previous route.
|
* previous route.
|
||||||
*
|
*
|
||||||
* If `canReuse` returns or resolves to `true`, the component instance will be reused and the
|
* If `routerCanReuse` returns or resolves to `true`, the component instance will be reused and the
|
||||||
* {@link OnDeactivate} hook will be run. If `canReuse` returns or resolves to `false`, a new
|
* {@link OnDeactivate} hook will be run. If `routerCanReuse` returns or resolves to `false`, a new
|
||||||
* component will be instantiated, and the existing component will be deactivated and removed as
|
* component will be instantiated, and the existing component will be deactivated and removed as
|
||||||
* part of the navigation.
|
* part of the navigation.
|
||||||
*
|
*
|
||||||
* If `canReuse` throws or rejects, the navigation will be cancelled.
|
* If `routerCanReuse` throws or rejects, the navigation will be cancelled.
|
||||||
*
|
*
|
||||||
* ### Example
|
* ### Example
|
||||||
* {@example router/ts/reuse/reuse_example.ts region='reuseCmp'}
|
* {@example router/ts/reuse/reuse_example.ts region='reuseCmp'}
|
||||||
*/
|
*/
|
||||||
export interface CanReuse {
|
export interface CanReuse {
|
||||||
canReuse(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction): any;
|
routerCanReuse(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction): any;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines route lifecycle method `canDeactivate`, which is called by the router to determine
|
* Defines route lifecycle method `routerCanDeactivate`, which is called by the router to determine
|
||||||
* if a component can be removed as part of a navigation.
|
* if a component can be removed as part of a navigation.
|
||||||
*
|
*
|
||||||
* The `canDeactivate` hook is called with two {@link ComponentInstruction}s as parameters, the
|
* The `routerCanDeactivate` hook is called with two {@link ComponentInstruction}s as parameters,
|
||||||
|
* the
|
||||||
* first representing the current route being navigated to, and the second parameter
|
* first representing the current route being navigated to, and the second parameter
|
||||||
* representing the previous route.
|
* representing the previous route.
|
||||||
*
|
*
|
||||||
* If `canDeactivate` returns or resolves to `false`, the navigation is cancelled. If it returns or
|
* If `routerCanDeactivate` returns or resolves to `false`, the navigation is cancelled. If it
|
||||||
|
* returns or
|
||||||
* resolves to `true`, then the navigation continues, and the component will be deactivated
|
* resolves to `true`, then the navigation continues, and the component will be deactivated
|
||||||
* (the {@link OnDeactivate} hook will be run) and removed.
|
* (the {@link OnDeactivate} hook will be run) and removed.
|
||||||
*
|
*
|
||||||
* If `canDeactivate` throws or rejects, the navigation is also cancelled.
|
* If `routerCanDeactivate` throws or rejects, the navigation is also cancelled.
|
||||||
*
|
*
|
||||||
* ### Example
|
* ### Example
|
||||||
* {@example router/ts/can_deactivate/can_deactivate_example.ts region='canDeactivate'}
|
* {@example router/ts/can_deactivate/can_deactivate_example.ts region='routerCanDeactivate'}
|
||||||
*/
|
*/
|
||||||
export interface CanDeactivate {
|
export interface CanDeactivate {
|
||||||
canDeactivate(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction): any;
|
routerCanDeactivate(nextInstruction: ComponentInstruction,
|
||||||
|
prevInstruction: ComponentInstruction): any;
|
||||||
}
|
}
|
||||||
|
@ -9,11 +9,11 @@ import {Promise} from 'angular2/src/facade/async';
|
|||||||
import {ComponentInstruction} from './instruction';
|
import {ComponentInstruction} from './instruction';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
canReuse,
|
routerCanReuse,
|
||||||
canDeactivate,
|
routerCanDeactivate,
|
||||||
onActivate,
|
routerOnActivate,
|
||||||
onReuse,
|
routerOnReuse,
|
||||||
onDeactivate
|
routerOnDeactivate
|
||||||
} from './lifecycle_annotations_impl';
|
} from './lifecycle_annotations_impl';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,9 +10,13 @@ export class CanActivate {
|
|||||||
constructor(public fn: Function) {}
|
constructor(public fn: Function) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const canReuse: RouteLifecycleHook = CONST_EXPR(new RouteLifecycleHook("canReuse"));
|
export const routerCanReuse: RouteLifecycleHook =
|
||||||
export const canDeactivate: RouteLifecycleHook =
|
CONST_EXPR(new RouteLifecycleHook("routerCanReuse"));
|
||||||
CONST_EXPR(new RouteLifecycleHook("canDeactivate"));
|
export const routerCanDeactivate: RouteLifecycleHook =
|
||||||
export const onActivate: RouteLifecycleHook = CONST_EXPR(new RouteLifecycleHook("onActivate"));
|
CONST_EXPR(new RouteLifecycleHook("routerCanDeactivate"));
|
||||||
export const onReuse: RouteLifecycleHook = CONST_EXPR(new RouteLifecycleHook("onReuse"));
|
export const routerOnActivate: RouteLifecycleHook =
|
||||||
export const onDeactivate: RouteLifecycleHook = CONST_EXPR(new RouteLifecycleHook("onDeactivate"));
|
CONST_EXPR(new RouteLifecycleHook("routerOnActivate"));
|
||||||
|
export const routerOnReuse: RouteLifecycleHook =
|
||||||
|
CONST_EXPR(new RouteLifecycleHook("routerOnReuse"));
|
||||||
|
export const routerOnDeactivate: RouteLifecycleHook =
|
||||||
|
CONST_EXPR(new RouteLifecycleHook("routerOnDeactivate"));
|
||||||
|
@ -10,15 +10,15 @@ bool hasLifecycleHook(RouteLifecycleHook e, type) {
|
|||||||
final List interfaces = reflector.interfaces(type);
|
final List interfaces = reflector.interfaces(type);
|
||||||
var interface;
|
var interface;
|
||||||
|
|
||||||
if (e == onActivate) {
|
if (e == routerOnActivate) {
|
||||||
interface = OnActivate;
|
interface = OnActivate;
|
||||||
} else if (e == onDeactivate) {
|
} else if (e == routerOnDeactivate) {
|
||||||
interface = OnDeactivate;
|
interface = OnDeactivate;
|
||||||
} else if (e == onReuse) {
|
} else if (e == routerOnReuse) {
|
||||||
interface = OnReuse;
|
interface = OnReuse;
|
||||||
} else if (e == canDeactivate) {
|
} else if (e == routerCanDeactivate) {
|
||||||
interface = CanDeactivate;
|
interface = CanDeactivate;
|
||||||
} else if (e == canReuse) {
|
} else if (e == routerCanReuse) {
|
||||||
interface = CanReuse;
|
interface = CanReuse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,13 +202,13 @@ export class Router {
|
|||||||
/** @internal */
|
/** @internal */
|
||||||
_navigate(instruction: Instruction, _skipLocationChange: boolean): Promise<any> {
|
_navigate(instruction: Instruction, _skipLocationChange: boolean): Promise<any> {
|
||||||
return this._settleInstruction(instruction)
|
return this._settleInstruction(instruction)
|
||||||
.then((_) => this._canReuse(instruction))
|
.then((_) => this._routerCanReuse(instruction))
|
||||||
.then((_) => this._canActivate(instruction))
|
.then((_) => this._canActivate(instruction))
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
if (!result) {
|
if (!result) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return this._canDeactivate(instruction)
|
return this._routerCanDeactivate(instruction)
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
if (result) {
|
if (result) {
|
||||||
return this.commit(instruction, _skipLocationChange)
|
return this.commit(instruction, _skipLocationChange)
|
||||||
@ -252,15 +252,15 @@ export class Router {
|
|||||||
* Recursively set reuse flags
|
* Recursively set reuse flags
|
||||||
*/
|
*/
|
||||||
/** @internal */
|
/** @internal */
|
||||||
_canReuse(instruction: Instruction): Promise<any> {
|
_routerCanReuse(instruction: Instruction): Promise<any> {
|
||||||
if (isBlank(this._outlet)) {
|
if (isBlank(this._outlet)) {
|
||||||
return _resolveToFalse;
|
return _resolveToFalse;
|
||||||
}
|
}
|
||||||
return this._outlet.canReuse(instruction.component)
|
return this._outlet.routerCanReuse(instruction.component)
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
instruction.component.reuse = result;
|
instruction.component.reuse = result;
|
||||||
if (result && isPresent(this._childRouter) && isPresent(instruction.child)) {
|
if (result && isPresent(this._childRouter) && isPresent(instruction.child)) {
|
||||||
return this._childRouter._canReuse(instruction.child);
|
return this._childRouter._routerCanReuse(instruction.child);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -269,7 +269,7 @@ export class Router {
|
|||||||
return canActivateOne(nextInstruction, this._currentInstruction);
|
return canActivateOne(nextInstruction, this._currentInstruction);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _canDeactivate(instruction: Instruction): Promise<boolean> {
|
private _routerCanDeactivate(instruction: Instruction): Promise<boolean> {
|
||||||
if (isBlank(this._outlet)) {
|
if (isBlank(this._outlet)) {
|
||||||
return _resolveToTrue;
|
return _resolveToTrue;
|
||||||
}
|
}
|
||||||
@ -285,7 +285,7 @@ export class Router {
|
|||||||
if (reuse) {
|
if (reuse) {
|
||||||
next = _resolveToTrue;
|
next = _resolveToTrue;
|
||||||
} else {
|
} else {
|
||||||
next = this._outlet.canDeactivate(componentInstruction);
|
next = this._outlet.routerCanDeactivate(componentInstruction);
|
||||||
}
|
}
|
||||||
// TODO: aux route lifecycle hooks
|
// TODO: aux route lifecycle hooks
|
||||||
return next.then((result) => {
|
return next.then((result) => {
|
||||||
@ -293,7 +293,7 @@ export class Router {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (isPresent(this._childRouter)) {
|
if (isPresent(this._childRouter)) {
|
||||||
return this._childRouter._canDeactivate(childInstruction);
|
return this._childRouter._routerCanDeactivate(childInstruction);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
@ -18,6 +18,7 @@ import * as routerMod from './router';
|
|||||||
import {ComponentInstruction, RouteParams, RouteData} from './instruction';
|
import {ComponentInstruction, RouteParams, RouteData} from './instruction';
|
||||||
import * as hookMod from './lifecycle_annotations';
|
import * as hookMod from './lifecycle_annotations';
|
||||||
import {hasLifecycleHook} from './route_lifecycle_reflector';
|
import {hasLifecycleHook} from './route_lifecycle_reflector';
|
||||||
|
import {OnActivate, CanReuse, OnReuse, OnDeactivate, CanDeactivate} from './interfaces';
|
||||||
|
|
||||||
let _resolveToTrue = PromiseWrapper.resolve(true);
|
let _resolveToTrue = PromiseWrapper.resolve(true);
|
||||||
|
|
||||||
@ -48,7 +49,7 @@ export class RouterOutlet {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the Router to instantiate a new component during the commit phase of a navigation.
|
* Called by the Router to instantiate a new component during the commit phase of a navigation.
|
||||||
* This method in turn is responsible for calling the `onActivate` hook of its child.
|
* This method in turn is responsible for calling the `routerOnActivate` hook of its child.
|
||||||
*/
|
*/
|
||||||
activate(nextInstruction: ComponentInstruction): Promise<any> {
|
activate(nextInstruction: ComponentInstruction): Promise<any> {
|
||||||
var previousInstruction = this._currentInstruction;
|
var previousInstruction = this._currentInstruction;
|
||||||
@ -64,8 +65,9 @@ export class RouterOutlet {
|
|||||||
return this._loader.loadNextToLocation(componentType, this._elementRef, providers)
|
return this._loader.loadNextToLocation(componentType, this._elementRef, providers)
|
||||||
.then((componentRef) => {
|
.then((componentRef) => {
|
||||||
this._componentRef = componentRef;
|
this._componentRef = componentRef;
|
||||||
if (hasLifecycleHook(hookMod.onActivate, componentType)) {
|
if (hasLifecycleHook(hookMod.routerOnActivate, componentType)) {
|
||||||
return this._componentRef.instance.onActivate(nextInstruction, previousInstruction);
|
return (<OnActivate>this._componentRef.instance)
|
||||||
|
.routerOnActivate(nextInstruction, previousInstruction);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -73,7 +75,7 @@ export class RouterOutlet {
|
|||||||
/**
|
/**
|
||||||
* Called by the {@link Router} during the commit phase of a navigation when an outlet
|
* Called by the {@link Router} during the commit phase of a navigation when an outlet
|
||||||
* reuses a component between different routes.
|
* reuses a component between different routes.
|
||||||
* This method in turn is responsible for calling the `onReuse` hook of its child.
|
* This method in turn is responsible for calling the `routerOnReuse` hook of its child.
|
||||||
*/
|
*/
|
||||||
reuse(nextInstruction: ComponentInstruction): Promise<any> {
|
reuse(nextInstruction: ComponentInstruction): Promise<any> {
|
||||||
var previousInstruction = this._currentInstruction;
|
var previousInstruction = this._currentInstruction;
|
||||||
@ -83,21 +85,23 @@ export class RouterOutlet {
|
|||||||
throw new BaseException(`Cannot reuse an outlet that does not contain a component.`);
|
throw new BaseException(`Cannot reuse an outlet that does not contain a component.`);
|
||||||
}
|
}
|
||||||
return PromiseWrapper.resolve(
|
return PromiseWrapper.resolve(
|
||||||
hasLifecycleHook(hookMod.onReuse, this._currentInstruction.componentType) ?
|
hasLifecycleHook(hookMod.routerOnReuse, this._currentInstruction.componentType) ?
|
||||||
this._componentRef.instance.onReuse(nextInstruction, previousInstruction) :
|
(<OnReuse>this._componentRef.instance)
|
||||||
|
.routerOnReuse(nextInstruction, previousInstruction) :
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the {@link Router} when an outlet disposes of a component's contents.
|
* Called by the {@link Router} when an outlet disposes of a component's contents.
|
||||||
* This method in turn is responsible for calling the `onDeactivate` hook of its child.
|
* This method in turn is responsible for calling the `routerOnDeactivate` hook of its child.
|
||||||
*/
|
*/
|
||||||
deactivate(nextInstruction: ComponentInstruction): Promise<any> {
|
deactivate(nextInstruction: ComponentInstruction): Promise<any> {
|
||||||
var next = _resolveToTrue;
|
var next = _resolveToTrue;
|
||||||
if (isPresent(this._componentRef) && isPresent(this._currentInstruction) &&
|
if (isPresent(this._componentRef) && isPresent(this._currentInstruction) &&
|
||||||
hasLifecycleHook(hookMod.onDeactivate, this._currentInstruction.componentType)) {
|
hasLifecycleHook(hookMod.routerOnDeactivate, this._currentInstruction.componentType)) {
|
||||||
next = PromiseWrapper.resolve(
|
next = PromiseWrapper.resolve(
|
||||||
this._componentRef.instance.onDeactivate(nextInstruction, this._currentInstruction));
|
(<OnDeactivate>this._componentRef.instance)
|
||||||
|
.routerOnDeactivate(nextInstruction, this._currentInstruction));
|
||||||
}
|
}
|
||||||
return next.then((_) => {
|
return next.then((_) => {
|
||||||
if (isPresent(this._componentRef)) {
|
if (isPresent(this._componentRef)) {
|
||||||
@ -112,16 +116,17 @@ export class RouterOutlet {
|
|||||||
*
|
*
|
||||||
* If this resolves to `false`, the given navigation is cancelled.
|
* If this resolves to `false`, the given navigation is cancelled.
|
||||||
*
|
*
|
||||||
* This method delegates to the child component's `canDeactivate` hook if it exists,
|
* This method delegates to the child component's `routerCanDeactivate` hook if it exists,
|
||||||
* and otherwise resolves to true.
|
* and otherwise resolves to true.
|
||||||
*/
|
*/
|
||||||
canDeactivate(nextInstruction: ComponentInstruction): Promise<boolean> {
|
routerCanDeactivate(nextInstruction: ComponentInstruction): Promise<boolean> {
|
||||||
if (isBlank(this._currentInstruction)) {
|
if (isBlank(this._currentInstruction)) {
|
||||||
return _resolveToTrue;
|
return _resolveToTrue;
|
||||||
}
|
}
|
||||||
if (hasLifecycleHook(hookMod.canDeactivate, this._currentInstruction.componentType)) {
|
if (hasLifecycleHook(hookMod.routerCanDeactivate, this._currentInstruction.componentType)) {
|
||||||
return PromiseWrapper.resolve(
|
return PromiseWrapper.resolve(
|
||||||
this._componentRef.instance.canDeactivate(nextInstruction, this._currentInstruction));
|
(<CanDeactivate>this._componentRef.instance)
|
||||||
|
.routerCanDeactivate(nextInstruction, this._currentInstruction));
|
||||||
}
|
}
|
||||||
return _resolveToTrue;
|
return _resolveToTrue;
|
||||||
}
|
}
|
||||||
@ -133,17 +138,18 @@ export class RouterOutlet {
|
|||||||
* this will resolve to `false`. You can't reuse an old component when the new component
|
* this will resolve to `false`. You can't reuse an old component when the new component
|
||||||
* is of a different Type.
|
* is of a different Type.
|
||||||
*
|
*
|
||||||
* Otherwise, this method delegates to the child component's `canReuse` hook if it exists,
|
* Otherwise, this method delegates to the child component's `routerCanReuse` hook if it exists,
|
||||||
* or resolves to true if the hook is not present.
|
* or resolves to true if the hook is not present.
|
||||||
*/
|
*/
|
||||||
canReuse(nextInstruction: ComponentInstruction): Promise<boolean> {
|
routerCanReuse(nextInstruction: ComponentInstruction): Promise<boolean> {
|
||||||
var result;
|
var result;
|
||||||
|
|
||||||
if (isBlank(this._currentInstruction) ||
|
if (isBlank(this._currentInstruction) ||
|
||||||
this._currentInstruction.componentType != nextInstruction.componentType) {
|
this._currentInstruction.componentType != nextInstruction.componentType) {
|
||||||
result = false;
|
result = false;
|
||||||
} else if (hasLifecycleHook(hookMod.canReuse, this._currentInstruction.componentType)) {
|
} else if (hasLifecycleHook(hookMod.routerCanReuse, this._currentInstruction.componentType)) {
|
||||||
result = this._componentRef.instance.canReuse(nextInstruction, this._currentInstruction);
|
result = (<CanReuse>this._componentRef.instance)
|
||||||
|
.routerCanReuse(nextInstruction, this._currentInstruction);
|
||||||
} else {
|
} else {
|
||||||
result = nextInstruction == this._currentInstruction ||
|
result = nextInstruction == this._currentInstruction ||
|
||||||
(isPresent(nextInstruction.params) && isPresent(this._currentInstruction.params) &&
|
(isPresent(nextInstruction.params) && isPresent(this._currentInstruction.params) &&
|
||||||
|
@ -5,6 +5,7 @@ import {
|
|||||||
ChangeDetectorRef,
|
ChangeDetectorRef,
|
||||||
HostViewRef,
|
HostViewRef,
|
||||||
Injector,
|
Injector,
|
||||||
|
OnChanges,
|
||||||
ProtoViewRef,
|
ProtoViewRef,
|
||||||
SimpleChange
|
SimpleChange
|
||||||
} from 'angular2/angular2';
|
} from 'angular2/angular2';
|
||||||
@ -91,13 +92,13 @@ export class DowngradeNg2ComponentAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var prototype = this.info.type.prototype;
|
var prototype = this.info.type.prototype;
|
||||||
if (prototype && prototype.onChanges) {
|
if (prototype && (<OnChanges>prototype).ngOnChanges) {
|
||||||
// Detect: OnChanges interface
|
// Detect: OnChanges interface
|
||||||
this.inputChanges = {};
|
this.inputChanges = {};
|
||||||
this.componentScope.$watch(() => this.inputChangeCount, () => {
|
this.componentScope.$watch(() => this.inputChangeCount, () => {
|
||||||
var inputChanges = this.inputChanges;
|
var inputChanges = this.inputChanges;
|
||||||
this.inputChanges = {};
|
this.inputChanges = {};
|
||||||
this.component.onChanges(inputChanges);
|
(<OnChanges>this.component).ngOnChanges(inputChanges);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.componentScope.$watch(() => this.changeDetector && this.changeDetector.detectChanges());
|
this.componentScope.$watch(() => this.changeDetector && this.changeDetector.detectChanges());
|
||||||
|
@ -53,8 +53,8 @@ export class UpgradeNg1ComponentAdapterBuilder {
|
|||||||
self.outputs, self.propertyOutputs, self.checkProperties, self.propertyMap);
|
self.outputs, self.propertyOutputs, self.checkProperties, self.propertyMap);
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
onChanges: function() { /* needs to be here for ng2 to properly detect it */ },
|
ngOnChanges: function() { /* needs to be here for ng2 to properly detect it */ },
|
||||||
doCheck: function() { /* needs to be here for ng2 to properly detect it */ }
|
ngDoCheck: function() { /* needs to be here for ng2 to properly detect it */ }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,7 +224,7 @@ class UpgradeNg1ComponentAdapter implements OnChanges, DoCheck {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onChanges(changes: {[name: string]: SimpleChange}) {
|
ngOnChanges(changes: {[name: string]: SimpleChange}) {
|
||||||
for (var name in changes) {
|
for (var name in changes) {
|
||||||
if ((<Object>changes).hasOwnProperty(name)) {
|
if ((<Object>changes).hasOwnProperty(name)) {
|
||||||
var change: SimpleChange = changes[name];
|
var change: SimpleChange = changes[name];
|
||||||
@ -233,7 +233,7 @@ class UpgradeNg1ComponentAdapter implements OnChanges, DoCheck {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
doCheck(): number {
|
ngDoCheck(): number {
|
||||||
var count = 0;
|
var count = 0;
|
||||||
var destinationObj = this.destinationObj;
|
var destinationObj = this.destinationObj;
|
||||||
var lastValues = this.checkLastValues;
|
var lastValues = this.checkLastValues;
|
||||||
|
@ -256,13 +256,13 @@ export function main() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("onChanges", () => {
|
describe("ngOnChanges", () => {
|
||||||
it("should update dom values of all the directives", () => {
|
it("should update dom values of all the directives", () => {
|
||||||
form.addControl(loginControlDir);
|
form.addControl(loginControlDir);
|
||||||
|
|
||||||
(<Control>formModel.find(["login"])).updateValue("new value");
|
(<Control>formModel.find(["login"])).updateValue("new value");
|
||||||
|
|
||||||
form.onChanges({});
|
form.ngOnChanges({});
|
||||||
|
|
||||||
expect((<any>loginControlDir.valueAccessor).writtenValue).toEqual("new value");
|
expect((<any>loginControlDir.valueAccessor).writtenValue).toEqual("new value");
|
||||||
});
|
});
|
||||||
@ -271,7 +271,7 @@ export function main() {
|
|||||||
var formValidator = (c) => ({"custom": true});
|
var formValidator = (c) => ({"custom": true});
|
||||||
var f = new NgFormModel([formValidator], []);
|
var f = new NgFormModel([formValidator], []);
|
||||||
f.form = formModel;
|
f.form = formModel;
|
||||||
f.onChanges({"form": new SimpleChange(null, null)});
|
f.ngOnChanges({"form": new SimpleChange(null, null)});
|
||||||
|
|
||||||
expect(formModel.errors).toEqual({"custom": true});
|
expect(formModel.errors).toEqual({"custom": true});
|
||||||
});
|
});
|
||||||
@ -279,7 +279,7 @@ export function main() {
|
|||||||
it("should set up an async validator", fakeAsync(() => {
|
it("should set up an async validator", fakeAsync(() => {
|
||||||
var f = new NgFormModel([], [asyncValidator("expected")]);
|
var f = new NgFormModel([], [asyncValidator("expected")]);
|
||||||
f.form = formModel;
|
f.form = formModel;
|
||||||
f.onChanges({"form": new SimpleChange(null, null)});
|
f.ngOnChanges({"form": new SimpleChange(null, null)});
|
||||||
|
|
||||||
tick();
|
tick();
|
||||||
|
|
||||||
@ -417,7 +417,7 @@ export function main() {
|
|||||||
it("should reexport new control properties", () => {
|
it("should reexport new control properties", () => {
|
||||||
var newControl = new Control(null);
|
var newControl = new Control(null);
|
||||||
controlDir.form = newControl;
|
controlDir.form = newControl;
|
||||||
controlDir.onChanges({"form": new SimpleChange(control, newControl)});
|
controlDir.ngOnChanges({"form": new SimpleChange(control, newControl)});
|
||||||
|
|
||||||
checkProperties(newControl);
|
checkProperties(newControl);
|
||||||
});
|
});
|
||||||
@ -426,7 +426,7 @@ export function main() {
|
|||||||
expect(control.valid).toBe(true);
|
expect(control.valid).toBe(true);
|
||||||
|
|
||||||
// this will add the required validator and recalculate the validity
|
// this will add the required validator and recalculate the validity
|
||||||
controlDir.onChanges({"form": new SimpleChange(null, control)});
|
controlDir.ngOnChanges({"form": new SimpleChange(null, control)});
|
||||||
|
|
||||||
expect(control.valid).toBe(false);
|
expect(control.valid).toBe(false);
|
||||||
});
|
});
|
||||||
@ -455,7 +455,7 @@ export function main() {
|
|||||||
|
|
||||||
it("should set up validator", fakeAsync(() => {
|
it("should set up validator", fakeAsync(() => {
|
||||||
// this will add the required validator and recalculate the validity
|
// this will add the required validator and recalculate the validity
|
||||||
ngModel.onChanges({});
|
ngModel.ngOnChanges({});
|
||||||
tick();
|
tick();
|
||||||
|
|
||||||
expect(ngModel.control.errors).toEqual({"required": true});
|
expect(ngModel.control.errors).toEqual({"required": true});
|
||||||
|
@ -153,13 +153,13 @@ export function main() {
|
|||||||
expect(c.value).toEqual("newValue");
|
expect(c.value).toEqual("newValue");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should invoke onChanges if it is present", () => {
|
it("should invoke ngOnChanges if it is present", () => {
|
||||||
var onChanges;
|
var ngOnChanges;
|
||||||
c.registerOnChange((v) => onChanges = ["invoked", v]);
|
c.registerOnChange((v) => ngOnChanges = ["invoked", v]);
|
||||||
|
|
||||||
c.updateValue("newValue");
|
c.updateValue("newValue");
|
||||||
|
|
||||||
expect(onChanges).toEqual(["invoked", "newValue"]);
|
expect(ngOnChanges).toEqual(["invoked", "newValue"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not invoke on change when explicitly specified", () => {
|
it("should not invoke on change when explicitly specified", () => {
|
||||||
|
@ -136,12 +136,12 @@ class DirectiveWithoutModuleId {
|
|||||||
class ComponentWithEverything implements OnChanges,
|
class ComponentWithEverything implements OnChanges,
|
||||||
OnInit, DoCheck, OnDestroy, AfterContentInit, AfterContentChecked, AfterViewInit,
|
OnInit, DoCheck, OnDestroy, AfterContentInit, AfterContentChecked, AfterViewInit,
|
||||||
AfterViewChecked {
|
AfterViewChecked {
|
||||||
onChanges(changes: {[key: string]: SimpleChange}): void {}
|
ngOnChanges(changes: {[key: string]: SimpleChange}): void {}
|
||||||
onInit(): void {}
|
ngOnInit(): void {}
|
||||||
doCheck(): void {}
|
ngDoCheck(): void {}
|
||||||
onDestroy(): void {}
|
ngOnDestroy(): void {}
|
||||||
afterContentInit(): void {}
|
ngAfterContentInit(): void {}
|
||||||
afterContentChecked(): void {}
|
ngAfterContentChecked(): void {}
|
||||||
afterViewInit(): void {}
|
ngAfterViewInit(): void {}
|
||||||
afterViewChecked(): void {}
|
ngAfterViewChecked(): void {}
|
||||||
}
|
}
|
||||||
|
@ -468,13 +468,13 @@ export function main() {
|
|||||||
it('should notify the dispatcher after content children have checked', () => {
|
it('should notify the dispatcher after content children have checked', () => {
|
||||||
var val = _createChangeDetector('name', new Person('bob'));
|
var val = _createChangeDetector('name', new Person('bob'));
|
||||||
val.changeDetector.detectChanges();
|
val.changeDetector.detectChanges();
|
||||||
expect(val.dispatcher.afterContentCheckedCalled).toEqual(true);
|
expect(val.dispatcher.ngAfterContentCheckedCalled).toEqual(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should notify the dispatcher after view children have been checked', () => {
|
it('should notify the dispatcher after view children have been checked', () => {
|
||||||
var val = _createChangeDetector('name', new Person('bob'));
|
var val = _createChangeDetector('name', new Person('bob'));
|
||||||
val.changeDetector.detectChanges();
|
val.changeDetector.detectChanges();
|
||||||
expect(val.dispatcher.afterViewCheckedCalled).toEqual(true);
|
expect(val.dispatcher.ngAfterViewCheckedCalled).toEqual(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('updating directives', () => {
|
describe('updating directives', () => {
|
||||||
@ -498,7 +498,7 @@ export function main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('lifecycle', () => {
|
describe('lifecycle', () => {
|
||||||
describe('onChanges', () => {
|
describe('ngOnChanges', () => {
|
||||||
it('should notify the directive when a group of records changes', () => {
|
it('should notify the directive when a group of records changes', () => {
|
||||||
var cd = _createWithoutHydrate('groupChanges').changeDetector;
|
var cd = _createWithoutHydrate('groupChanges').changeDetector;
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1, directive2], []),
|
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1, directive2], []),
|
||||||
@ -509,32 +509,32 @@ export function main() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('doCheck', () => {
|
describe('ngDoCheck', () => {
|
||||||
it('should notify the directive when it is checked', () => {
|
it('should notify the directive when it is checked', () => {
|
||||||
var cd = _createWithoutHydrate('directiveDoCheck').changeDetector;
|
var cd = _createWithoutHydrate('directiveDoCheck').changeDetector;
|
||||||
|
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
|
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
expect(directive1.doCheckCalled).toBe(true);
|
expect(directive1.ngDoCheckCalled).toBe(true);
|
||||||
directive1.doCheckCalled = false;
|
directive1.ngDoCheckCalled = false;
|
||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
expect(directive1.doCheckCalled).toBe(true);
|
expect(directive1.ngDoCheckCalled).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not call doCheck in detectNoChanges', () => {
|
it('should not call ngDoCheck in detectNoChanges', () => {
|
||||||
var cd = _createWithoutHydrate('directiveDoCheck').changeDetector;
|
var cd = _createWithoutHydrate('directiveDoCheck').changeDetector;
|
||||||
|
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
|
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
|
||||||
|
|
||||||
cd.checkNoChanges();
|
cd.checkNoChanges();
|
||||||
|
|
||||||
expect(directive1.doCheckCalled).toBe(false);
|
expect(directive1.ngDoCheckCalled).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('onInit', () => {
|
describe('ngOnInit', () => {
|
||||||
it('should notify the directive after it has been checked the first time', () => {
|
it('should notify the directive after it has been checked the first time', () => {
|
||||||
var cd = _createWithoutHydrate('directiveOnInit').changeDetector;
|
var cd = _createWithoutHydrate('directiveOnInit').changeDetector;
|
||||||
|
|
||||||
@ -543,51 +543,51 @@ export function main() {
|
|||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
expect(directive1.onInitCalled).toBe(true);
|
expect(directive1.ngOnInitCalled).toBe(true);
|
||||||
|
|
||||||
directive1.onInitCalled = false;
|
directive1.ngOnInitCalled = false;
|
||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
expect(directive1.onInitCalled).toBe(false);
|
expect(directive1.ngOnInitCalled).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not call onInit in detectNoChanges', () => {
|
it('should not call ngOnInit in detectNoChanges', () => {
|
||||||
var cd = _createWithoutHydrate('directiveOnInit').changeDetector;
|
var cd = _createWithoutHydrate('directiveOnInit').changeDetector;
|
||||||
|
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
|
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
|
||||||
|
|
||||||
cd.checkNoChanges();
|
cd.checkNoChanges();
|
||||||
|
|
||||||
expect(directive1.onInitCalled).toBe(false);
|
expect(directive1.ngOnInitCalled).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not call onInit again if it throws', () => {
|
it('should not call ngOnInit again if it throws', () => {
|
||||||
var cd = _createWithoutHydrate('directiveOnInit').changeDetector;
|
var cd = _createWithoutHydrate('directiveOnInit').changeDetector;
|
||||||
|
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive3], []), null);
|
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive3], []), null);
|
||||||
var errored = false;
|
var errored = false;
|
||||||
// First pass fails, but onInit should be called.
|
// First pass fails, but ngOnInit should be called.
|
||||||
try {
|
try {
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errored = true;
|
errored = true;
|
||||||
}
|
}
|
||||||
expect(errored).toBe(true);
|
expect(errored).toBe(true);
|
||||||
expect(directive3.onInitCalled).toBe(true);
|
expect(directive3.ngOnInitCalled).toBe(true);
|
||||||
directive3.onInitCalled = false;
|
directive3.ngOnInitCalled = false;
|
||||||
|
|
||||||
// Second change detection also fails, but this time onInit should not be called.
|
// Second change detection also fails, but this time ngOnInit should not be called.
|
||||||
try {
|
try {
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new BaseException("Second detectChanges() should not have run detection.");
|
throw new BaseException("Second detectChanges() should not have run detection.");
|
||||||
}
|
}
|
||||||
expect(directive3.onInitCalled).toBe(false);
|
expect(directive3.ngOnInitCalled).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('afterContentInit', () => {
|
describe('ngAfterContentInit', () => {
|
||||||
it('should be called after processing the content children', () => {
|
it('should be called after processing the content children', () => {
|
||||||
var cd = _createWithoutHydrate('emptyWithDirectiveRecords').changeDetector;
|
var cd = _createWithoutHydrate('emptyWithDirectiveRecords').changeDetector;
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1, directive2], []),
|
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1, directive2], []),
|
||||||
@ -595,38 +595,38 @@ export function main() {
|
|||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
expect(directive1.afterContentInitCalled).toBe(true);
|
expect(directive1.ngAfterContentInitCalled).toBe(true);
|
||||||
expect(directive2.afterContentInitCalled).toBe(true);
|
expect(directive2.ngAfterContentInitCalled).toBe(true);
|
||||||
|
|
||||||
// reset directives
|
// reset directives
|
||||||
directive1.afterContentInitCalled = false;
|
directive1.ngAfterContentInitCalled = false;
|
||||||
directive2.afterContentInitCalled = false;
|
directive2.ngAfterContentInitCalled = false;
|
||||||
|
|
||||||
// Verify that checking should not call them.
|
// Verify that checking should not call them.
|
||||||
cd.checkNoChanges();
|
cd.checkNoChanges();
|
||||||
|
|
||||||
expect(directive1.afterContentInitCalled).toBe(false);
|
expect(directive1.ngAfterContentInitCalled).toBe(false);
|
||||||
expect(directive2.afterContentInitCalled).toBe(false);
|
expect(directive2.ngAfterContentInitCalled).toBe(false);
|
||||||
|
|
||||||
// re-verify that changes should not call them
|
// re-verify that changes should not call them
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
expect(directive1.afterContentInitCalled).toBe(false);
|
expect(directive1.ngAfterContentInitCalled).toBe(false);
|
||||||
expect(directive2.afterContentInitCalled).toBe(false);
|
expect(directive2.ngAfterContentInitCalled).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not be called when afterContentInit is false', () => {
|
it('should not be called when ngAfterContentInit is false', () => {
|
||||||
var cd = _createWithoutHydrate('noCallbacks').changeDetector;
|
var cd = _createWithoutHydrate('noCallbacks').changeDetector;
|
||||||
|
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
|
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
|
||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
expect(directive1.afterContentInitCalled).toEqual(false);
|
expect(directive1.ngAfterContentInitCalled).toEqual(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('afterContentChecked', () => {
|
describe('ngAfterContentChecked', () => {
|
||||||
it('should be called after processing all the children', () => {
|
it('should be called after processing all the children', () => {
|
||||||
var cd = _createWithoutHydrate('emptyWithDirectiveRecords').changeDetector;
|
var cd = _createWithoutHydrate('emptyWithDirectiveRecords').changeDetector;
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1, directive2], []),
|
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1, directive2], []),
|
||||||
@ -634,50 +634,50 @@ export function main() {
|
|||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
expect(directive1.afterContentCheckedCalled).toBe(true);
|
expect(directive1.ngAfterContentCheckedCalled).toBe(true);
|
||||||
expect(directive2.afterContentCheckedCalled).toBe(true);
|
expect(directive2.ngAfterContentCheckedCalled).toBe(true);
|
||||||
|
|
||||||
// reset directives
|
// reset directives
|
||||||
directive1.afterContentCheckedCalled = false;
|
directive1.ngAfterContentCheckedCalled = false;
|
||||||
directive2.afterContentCheckedCalled = false;
|
directive2.ngAfterContentCheckedCalled = false;
|
||||||
|
|
||||||
// Verify that checking should not call them.
|
// Verify that checking should not call them.
|
||||||
cd.checkNoChanges();
|
cd.checkNoChanges();
|
||||||
|
|
||||||
expect(directive1.afterContentCheckedCalled).toBe(false);
|
expect(directive1.ngAfterContentCheckedCalled).toBe(false);
|
||||||
expect(directive2.afterContentCheckedCalled).toBe(false);
|
expect(directive2.ngAfterContentCheckedCalled).toBe(false);
|
||||||
|
|
||||||
// re-verify that changes are still detected
|
// re-verify that changes are still detected
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
expect(directive1.afterContentCheckedCalled).toBe(true);
|
expect(directive1.ngAfterContentCheckedCalled).toBe(true);
|
||||||
expect(directive2.afterContentCheckedCalled).toBe(true);
|
expect(directive2.ngAfterContentCheckedCalled).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not be called when afterContentChecked is false', () => {
|
it('should not be called when ngAfterContentChecked is false', () => {
|
||||||
var cd = _createWithoutHydrate('noCallbacks').changeDetector;
|
var cd = _createWithoutHydrate('noCallbacks').changeDetector;
|
||||||
|
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
|
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
|
||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
expect(directive1.afterContentCheckedCalled).toEqual(false);
|
expect(directive1.ngAfterContentCheckedCalled).toEqual(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be called in reverse order so the child is always notified before the parent',
|
it('should be called in reverse order so the child is always notified before the parent',
|
||||||
() => {
|
() => {
|
||||||
var cd = _createWithoutHydrate('emptyWithDirectiveRecords').changeDetector;
|
var cd = _createWithoutHydrate('emptyWithDirectiveRecords').changeDetector;
|
||||||
|
|
||||||
var onChangesDoneCalls = [];
|
var ngOnChangesDoneCalls = [];
|
||||||
var td1;
|
var td1;
|
||||||
td1 = new TestDirective(() => onChangesDoneCalls.push(td1));
|
td1 = new TestDirective(() => ngOnChangesDoneCalls.push(td1));
|
||||||
var td2;
|
var td2;
|
||||||
td2 = new TestDirective(() => onChangesDoneCalls.push(td2));
|
td2 = new TestDirective(() => ngOnChangesDoneCalls.push(td2));
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([td1, td2], []), null);
|
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([td1, td2], []), null);
|
||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
expect(onChangesDoneCalls).toEqual([td2, td1]);
|
expect(ngOnChangesDoneCalls).toEqual([td2, td1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be called before processing view children', () => {
|
it('should be called before processing view children', () => {
|
||||||
@ -705,7 +705,7 @@ export function main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('afterViewInit', () => {
|
describe('ngAfterViewInit', () => {
|
||||||
it('should be called after processing the view children', () => {
|
it('should be called after processing the view children', () => {
|
||||||
var cd = _createWithoutHydrate('emptyWithDirectiveRecords').changeDetector;
|
var cd = _createWithoutHydrate('emptyWithDirectiveRecords').changeDetector;
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1, directive2], []),
|
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1, directive2], []),
|
||||||
@ -713,39 +713,39 @@ export function main() {
|
|||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
expect(directive1.afterViewInitCalled).toBe(true);
|
expect(directive1.ngAfterViewInitCalled).toBe(true);
|
||||||
expect(directive2.afterViewInitCalled).toBe(true);
|
expect(directive2.ngAfterViewInitCalled).toBe(true);
|
||||||
|
|
||||||
// reset directives
|
// reset directives
|
||||||
directive1.afterViewInitCalled = false;
|
directive1.ngAfterViewInitCalled = false;
|
||||||
directive2.afterViewInitCalled = false;
|
directive2.ngAfterViewInitCalled = false;
|
||||||
|
|
||||||
// Verify that checking should not call them.
|
// Verify that checking should not call them.
|
||||||
cd.checkNoChanges();
|
cd.checkNoChanges();
|
||||||
|
|
||||||
expect(directive1.afterViewInitCalled).toBe(false);
|
expect(directive1.ngAfterViewInitCalled).toBe(false);
|
||||||
expect(directive2.afterViewInitCalled).toBe(false);
|
expect(directive2.ngAfterViewInitCalled).toBe(false);
|
||||||
|
|
||||||
// re-verify that changes should not call them
|
// re-verify that changes should not call them
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
expect(directive1.afterViewInitCalled).toBe(false);
|
expect(directive1.ngAfterViewInitCalled).toBe(false);
|
||||||
expect(directive2.afterViewInitCalled).toBe(false);
|
expect(directive2.ngAfterViewInitCalled).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should not be called when afterViewInit is false', () => {
|
it('should not be called when ngAfterViewInit is false', () => {
|
||||||
var cd = _createWithoutHydrate('noCallbacks').changeDetector;
|
var cd = _createWithoutHydrate('noCallbacks').changeDetector;
|
||||||
|
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
|
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
|
||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
expect(directive1.afterViewInitCalled).toEqual(false);
|
expect(directive1.ngAfterViewInitCalled).toEqual(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('afterViewChecked', () => {
|
describe('ngAfterViewChecked', () => {
|
||||||
it('should be called after processing the view children', () => {
|
it('should be called after processing the view children', () => {
|
||||||
var cd = _createWithoutHydrate('emptyWithDirectiveRecords').changeDetector;
|
var cd = _createWithoutHydrate('emptyWithDirectiveRecords').changeDetector;
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1, directive2], []),
|
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1, directive2], []),
|
||||||
@ -753,50 +753,50 @@ export function main() {
|
|||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
expect(directive1.afterViewCheckedCalled).toBe(true);
|
expect(directive1.ngAfterViewCheckedCalled).toBe(true);
|
||||||
expect(directive2.afterViewCheckedCalled).toBe(true);
|
expect(directive2.ngAfterViewCheckedCalled).toBe(true);
|
||||||
|
|
||||||
// reset directives
|
// reset directives
|
||||||
directive1.afterViewCheckedCalled = false;
|
directive1.ngAfterViewCheckedCalled = false;
|
||||||
directive2.afterViewCheckedCalled = false;
|
directive2.ngAfterViewCheckedCalled = false;
|
||||||
|
|
||||||
// Verify that checking should not call them.
|
// Verify that checking should not call them.
|
||||||
cd.checkNoChanges();
|
cd.checkNoChanges();
|
||||||
|
|
||||||
expect(directive1.afterViewCheckedCalled).toBe(false);
|
expect(directive1.ngAfterViewCheckedCalled).toBe(false);
|
||||||
expect(directive2.afterViewCheckedCalled).toBe(false);
|
expect(directive2.ngAfterViewCheckedCalled).toBe(false);
|
||||||
|
|
||||||
// re-verify that changes should call them
|
// re-verify that changes should call them
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
expect(directive1.afterViewCheckedCalled).toBe(true);
|
expect(directive1.ngAfterViewCheckedCalled).toBe(true);
|
||||||
expect(directive2.afterViewCheckedCalled).toBe(true);
|
expect(directive2.ngAfterViewCheckedCalled).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not be called when afterViewChecked is false', () => {
|
it('should not be called when ngAfterViewChecked is false', () => {
|
||||||
var cd = _createWithoutHydrate('noCallbacks').changeDetector;
|
var cd = _createWithoutHydrate('noCallbacks').changeDetector;
|
||||||
|
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
|
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
|
||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
expect(directive1.afterViewCheckedCalled).toEqual(false);
|
expect(directive1.ngAfterViewCheckedCalled).toEqual(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be called in reverse order so the child is always notified before the parent',
|
it('should be called in reverse order so the child is always notified before the parent',
|
||||||
() => {
|
() => {
|
||||||
var cd = _createWithoutHydrate('emptyWithDirectiveRecords').changeDetector;
|
var cd = _createWithoutHydrate('emptyWithDirectiveRecords').changeDetector;
|
||||||
|
|
||||||
var onChangesDoneCalls = [];
|
var ngOnChangesDoneCalls = [];
|
||||||
var td1;
|
var td1;
|
||||||
td1 = new TestDirective(null, () => onChangesDoneCalls.push(td1));
|
td1 = new TestDirective(null, () => ngOnChangesDoneCalls.push(td1));
|
||||||
var td2;
|
var td2;
|
||||||
td2 = new TestDirective(null, () => onChangesDoneCalls.push(td2));
|
td2 = new TestDirective(null, () => ngOnChangesDoneCalls.push(td2));
|
||||||
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([td1, td2], []), null);
|
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([td1, td2], []), null);
|
||||||
|
|
||||||
cd.detectChanges();
|
cd.detectChanges();
|
||||||
|
|
||||||
expect(onChangesDoneCalls).toEqual([td2, td1]);
|
expect(ngOnChangesDoneCalls).toEqual([td2, td1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be called after processing view children', () => {
|
it('should be called after processing view children', () => {
|
||||||
@ -1408,51 +1408,51 @@ class TestDirective {
|
|||||||
a;
|
a;
|
||||||
b;
|
b;
|
||||||
changes;
|
changes;
|
||||||
doCheckCalled = false;
|
ngDoCheckCalled = false;
|
||||||
onInitCalled = false;
|
ngOnInitCalled = false;
|
||||||
|
|
||||||
afterContentInitCalled = false;
|
ngAfterContentInitCalled = false;
|
||||||
afterContentCheckedCalled = false;
|
ngAfterContentCheckedCalled = false;
|
||||||
|
|
||||||
afterViewInitCalled = false;
|
ngAfterViewInitCalled = false;
|
||||||
afterViewCheckedCalled = false;
|
ngAfterViewCheckedCalled = false;
|
||||||
event;
|
event;
|
||||||
|
|
||||||
constructor(public afterContentCheckedSpy = null, public afterViewCheckedSpy = null,
|
constructor(public ngAfterContentCheckedSpy = null, public ngAfterViewCheckedSpy = null,
|
||||||
public throwOnInit = false) {}
|
public throwOnInit = false) {}
|
||||||
|
|
||||||
onEvent(event) { this.event = event; }
|
onEvent(event) { this.event = event; }
|
||||||
|
|
||||||
doCheck() { this.doCheckCalled = true; }
|
ngDoCheck() { this.ngDoCheckCalled = true; }
|
||||||
|
|
||||||
onInit() {
|
ngOnInit() {
|
||||||
this.onInitCalled = true;
|
this.ngOnInitCalled = true;
|
||||||
if (this.throwOnInit) {
|
if (this.throwOnInit) {
|
||||||
throw "simulated onInit failure";
|
throw "simulated ngOnInit failure";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onChanges(changes) {
|
ngOnChanges(changes) {
|
||||||
var r = {};
|
var r = {};
|
||||||
StringMapWrapper.forEach(changes, (c, key) => r[key] = c.currentValue);
|
StringMapWrapper.forEach(changes, (c, key) => r[key] = c.currentValue);
|
||||||
this.changes = r;
|
this.changes = r;
|
||||||
}
|
}
|
||||||
|
|
||||||
afterContentInit() { this.afterContentInitCalled = true; }
|
ngAfterContentInit() { this.ngAfterContentInitCalled = true; }
|
||||||
|
|
||||||
afterContentChecked() {
|
ngAfterContentChecked() {
|
||||||
this.afterContentCheckedCalled = true;
|
this.ngAfterContentCheckedCalled = true;
|
||||||
if (isPresent(this.afterContentCheckedSpy)) {
|
if (isPresent(this.ngAfterContentCheckedSpy)) {
|
||||||
this.afterContentCheckedSpy();
|
this.ngAfterContentCheckedSpy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
afterViewInit() { this.afterViewInitCalled = true; }
|
ngAfterViewInit() { this.ngAfterViewInitCalled = true; }
|
||||||
|
|
||||||
afterViewChecked() {
|
ngAfterViewChecked() {
|
||||||
this.afterViewCheckedCalled = true;
|
this.ngAfterViewCheckedCalled = true;
|
||||||
if (isPresent(this.afterViewCheckedSpy)) {
|
if (isPresent(this.ngAfterViewCheckedSpy)) {
|
||||||
this.afterViewCheckedSpy();
|
this.ngAfterViewCheckedSpy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1531,8 +1531,8 @@ class TestDispatcher implements ChangeDispatcher {
|
|||||||
log: string[];
|
log: string[];
|
||||||
debugLog: string[];
|
debugLog: string[];
|
||||||
loggedValues: any[];
|
loggedValues: any[];
|
||||||
afterContentCheckedCalled: boolean = false;
|
ngAfterContentCheckedCalled: boolean = false;
|
||||||
afterViewCheckedCalled: boolean = false;
|
ngAfterViewCheckedCalled: boolean = false;
|
||||||
|
|
||||||
constructor() { this.clear(); }
|
constructor() { this.clear(); }
|
||||||
|
|
||||||
@ -1540,7 +1540,7 @@ class TestDispatcher implements ChangeDispatcher {
|
|||||||
this.log = [];
|
this.log = [];
|
||||||
this.debugLog = [];
|
this.debugLog = [];
|
||||||
this.loggedValues = [];
|
this.loggedValues = [];
|
||||||
this.afterContentCheckedCalled = true;
|
this.ngAfterContentCheckedCalled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyOnBinding(target, value) {
|
notifyOnBinding(target, value) {
|
||||||
@ -1550,8 +1550,8 @@ class TestDispatcher implements ChangeDispatcher {
|
|||||||
|
|
||||||
logBindingUpdate(target, value) { this.debugLog.push(`${target.name}=${this._asString(value)}`); }
|
logBindingUpdate(target, value) { this.debugLog.push(`${target.name}=${this._asString(value)}`); }
|
||||||
|
|
||||||
notifyAfterContentChecked() { this.afterContentCheckedCalled = true; }
|
notifyAfterContentChecked() { this.ngAfterContentCheckedCalled = true; }
|
||||||
notifyAfterViewChecked() { this.afterViewCheckedCalled = true; }
|
notifyAfterViewChecked() { this.ngAfterViewCheckedCalled = true; }
|
||||||
|
|
||||||
getDebugContext(a, b) { return null; }
|
getDebugContext(a, b) { return null; }
|
||||||
|
|
||||||
|
@ -84,8 +84,8 @@ export function main() {
|
|||||||
|
|
||||||
it("should not coalesce directive lifecycle records", () => {
|
it("should not coalesce directive lifecycle records", () => {
|
||||||
var rs = coalesce([
|
var rs = coalesce([
|
||||||
r("doCheck", [], 0, 1, {mode: RecordType.DirectiveLifecycle}),
|
r("ngDoCheck", [], 0, 1, {mode: RecordType.DirectiveLifecycle}),
|
||||||
r("doCheck", [], 0, 1, {mode: RecordType.DirectiveLifecycle})
|
r("ngDoCheck", [], 0, 1, {mode: RecordType.DirectiveLifecycle})
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(rs.length).toEqual(2);
|
expect(rs.length).toEqual(2);
|
||||||
|
@ -27,7 +27,7 @@ import {Directive, Component, View, ViewMetadata} from 'angular2/src/core/metada
|
|||||||
export function main() {
|
export function main() {
|
||||||
describe('directive lifecycle integration spec', () => {
|
describe('directive lifecycle integration spec', () => {
|
||||||
|
|
||||||
it('should invoke lifecycle methods onChanges > onInit > doCheck > afterContentChecked',
|
it('should invoke lifecycle methods ngOnChanges > ngOnInit > ngDoCheck > ngAfterContentChecked',
|
||||||
inject([TestComponentBuilder, Log, AsyncTestCompleter], (tcb: TestComponentBuilder, log: Log,
|
inject([TestComponentBuilder, Log, AsyncTestCompleter], (tcb: TestComponentBuilder, log: Log,
|
||||||
async) => {
|
async) => {
|
||||||
tcb.overrideView(
|
tcb.overrideView(
|
||||||
@ -40,14 +40,15 @@ export function main() {
|
|||||||
|
|
||||||
expect(log.result())
|
expect(log.result())
|
||||||
.toEqual(
|
.toEqual(
|
||||||
"onChanges; onInit; doCheck; afterContentInit; afterContentChecked; child_doCheck; " +
|
"ngOnChanges; ngOnInit; ngDoCheck; ngAfterContentInit; ngAfterContentChecked; child_ngDoCheck; " +
|
||||||
"afterViewInit; afterViewChecked");
|
"ngAfterViewInit; ngAfterViewChecked");
|
||||||
|
|
||||||
log.clear();
|
log.clear();
|
||||||
tc.detectChanges();
|
tc.detectChanges();
|
||||||
|
|
||||||
expect(log.result())
|
expect(log.result())
|
||||||
.toEqual("doCheck; afterContentChecked; child_doCheck; afterViewChecked");
|
.toEqual(
|
||||||
|
"ngDoCheck; ngAfterContentChecked; child_ngDoCheck; ngAfterViewChecked");
|
||||||
|
|
||||||
async.done();
|
async.done();
|
||||||
});
|
});
|
||||||
@ -59,7 +60,7 @@ export function main() {
|
|||||||
@Directive({selector: '[lifecycle-dir]'})
|
@Directive({selector: '[lifecycle-dir]'})
|
||||||
class LifecycleDir implements DoCheck {
|
class LifecycleDir implements DoCheck {
|
||||||
constructor(private _log: Log) {}
|
constructor(private _log: Log) {}
|
||||||
doCheck() { this._log.add("child_doCheck"); }
|
ngDoCheck() { this._log.add("child_ngDoCheck"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({selector: "[lifecycle]", inputs: ['field']})
|
@Component({selector: "[lifecycle]", inputs: ['field']})
|
||||||
@ -69,19 +70,19 @@ class LifecycleCmp implements OnChanges, OnInit, DoCheck, AfterContentInit, Afte
|
|||||||
field;
|
field;
|
||||||
constructor(private _log: Log) {}
|
constructor(private _log: Log) {}
|
||||||
|
|
||||||
onChanges(_) { this._log.add("onChanges"); }
|
ngOnChanges(_) { this._log.add("ngOnChanges"); }
|
||||||
|
|
||||||
onInit() { this._log.add("onInit"); }
|
ngOnInit() { this._log.add("ngOnInit"); }
|
||||||
|
|
||||||
doCheck() { this._log.add("doCheck"); }
|
ngDoCheck() { this._log.add("ngDoCheck"); }
|
||||||
|
|
||||||
afterContentInit() { this._log.add("afterContentInit"); }
|
ngAfterContentInit() { this._log.add("ngAfterContentInit"); }
|
||||||
|
|
||||||
afterContentChecked() { this._log.add("afterContentChecked"); }
|
ngAfterContentChecked() { this._log.add("ngAfterContentChecked"); }
|
||||||
|
|
||||||
afterViewInit() { this._log.add("afterViewInit"); }
|
ngAfterViewInit() { this._log.add("ngAfterViewInit"); }
|
||||||
|
|
||||||
afterViewChecked() { this._log.add("afterViewChecked"); }
|
ngAfterViewChecked() { this._log.add("ngAfterViewChecked"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({selector: 'my-comp'})
|
@Component({selector: 'my-comp'})
|
||||||
|
@ -7,8 +7,8 @@ import 'package:angular2/src/core/linker/interfaces.dart';
|
|||||||
main() {
|
main() {
|
||||||
describe('Create DirectiveMetadata', () {
|
describe('Create DirectiveMetadata', () {
|
||||||
describe('lifecycle', () {
|
describe('lifecycle', () {
|
||||||
describe("onChanges", () {
|
describe("ngOnChanges", () {
|
||||||
it("should be true when the directive has the onChanges method", () {
|
it("should be true when the directive has the ngOnChanges method", () {
|
||||||
expect(hasLifecycleHook(
|
expect(hasLifecycleHook(
|
||||||
LifecycleHooks.OnChanges, DirectiveImplementingOnChanges))
|
LifecycleHooks.OnChanges, DirectiveImplementingOnChanges))
|
||||||
.toBe(true);
|
.toBe(true);
|
||||||
@ -20,8 +20,8 @@ main() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("onDestroy", () {
|
describe("ngOnDestroy", () {
|
||||||
it("should be true when the directive has the onDestroy method", () {
|
it("should be true when the directive has the ngOnDestroy method", () {
|
||||||
expect(hasLifecycleHook(
|
expect(hasLifecycleHook(
|
||||||
LifecycleHooks.OnDestroy, DirectiveImplementingOnDestroy))
|
LifecycleHooks.OnDestroy, DirectiveImplementingOnDestroy))
|
||||||
.toBe(true);
|
.toBe(true);
|
||||||
@ -33,8 +33,8 @@ main() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("onInit", () {
|
describe("ngOnInit", () {
|
||||||
it("should be true when the directive has the onInit method", () {
|
it("should be true when the directive has the ngOnInit method", () {
|
||||||
expect(hasLifecycleHook(
|
expect(hasLifecycleHook(
|
||||||
LifecycleHooks.OnInit, DirectiveImplementingOnInit)).toBe(true);
|
LifecycleHooks.OnInit, DirectiveImplementingOnInit)).toBe(true);
|
||||||
});
|
});
|
||||||
@ -45,8 +45,8 @@ main() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("doCheck", () {
|
describe("ngDoCheck", () {
|
||||||
it("should be true when the directive has the doCheck method", () {
|
it("should be true when the directive has the ngDoCheck method", () {
|
||||||
expect(hasLifecycleHook(
|
expect(hasLifecycleHook(
|
||||||
LifecycleHooks.DoCheck, DirectiveImplementingOnCheck)).toBe(true);
|
LifecycleHooks.DoCheck, DirectiveImplementingOnCheck)).toBe(true);
|
||||||
});
|
});
|
||||||
@ -57,8 +57,8 @@ main() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("afterContentInit", () {
|
describe("ngAfterContentInit", () {
|
||||||
it("should be true when the directive has the afterContentInit method",
|
it("should be true when the directive has the ngAfterContentInit method",
|
||||||
() {
|
() {
|
||||||
expect(hasLifecycleHook(LifecycleHooks.AfterContentInit,
|
expect(hasLifecycleHook(LifecycleHooks.AfterContentInit,
|
||||||
DirectiveImplementingAfterContentInit)).toBe(true);
|
DirectiveImplementingAfterContentInit)).toBe(true);
|
||||||
@ -70,8 +70,8 @@ main() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("afterContentChecked", () {
|
describe("ngAfterContentChecked", () {
|
||||||
it("should be true when the directive has the afterContentChecked method",
|
it("should be true when the directive has the ngAfterContentChecked method",
|
||||||
() {
|
() {
|
||||||
expect(hasLifecycleHook(LifecycleHooks.AfterContentChecked,
|
expect(hasLifecycleHook(LifecycleHooks.AfterContentChecked,
|
||||||
DirectiveImplementingAfterContentChecked)).toBe(true);
|
DirectiveImplementingAfterContentChecked)).toBe(true);
|
||||||
@ -84,8 +84,8 @@ main() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("afterViewInit", () {
|
describe("ngAfterViewInit", () {
|
||||||
it("should be true when the directive has the afterViewInit method",
|
it("should be true when the directive has the ngAfterViewInit method",
|
||||||
() {
|
() {
|
||||||
expect(hasLifecycleHook(LifecycleHooks.AfterViewInit,
|
expect(hasLifecycleHook(LifecycleHooks.AfterViewInit,
|
||||||
DirectiveImplementingAfterViewInit)).toBe(true);
|
DirectiveImplementingAfterViewInit)).toBe(true);
|
||||||
@ -97,8 +97,8 @@ main() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("afterViewChecked", () {
|
describe("ngAfterViewChecked", () {
|
||||||
it("should be true when the directive has the afterViewChecked method",
|
it("should be true when the directive has the ngAfterViewChecked method",
|
||||||
() {
|
() {
|
||||||
expect(hasLifecycleHook(LifecycleHooks.AfterViewChecked,
|
expect(hasLifecycleHook(LifecycleHooks.AfterViewChecked,
|
||||||
DirectiveImplementingAfterViewChecked)).toBe(true);
|
DirectiveImplementingAfterViewChecked)).toBe(true);
|
||||||
@ -116,33 +116,33 @@ main() {
|
|||||||
class DirectiveNoHooks {}
|
class DirectiveNoHooks {}
|
||||||
|
|
||||||
class DirectiveImplementingOnChanges implements OnChanges {
|
class DirectiveImplementingOnChanges implements OnChanges {
|
||||||
onChanges(_) {}
|
ngOnChanges(_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DirectiveImplementingOnCheck implements DoCheck {
|
class DirectiveImplementingOnCheck implements DoCheck {
|
||||||
doCheck() {}
|
ngDoCheck() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DirectiveImplementingOnInit implements OnInit {
|
class DirectiveImplementingOnInit implements OnInit {
|
||||||
onInit() {}
|
ngOnInit() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DirectiveImplementingOnDestroy implements OnDestroy {
|
class DirectiveImplementingOnDestroy implements OnDestroy {
|
||||||
onDestroy() {}
|
ngOnDestroy() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DirectiveImplementingAfterContentInit implements AfterContentInit {
|
class DirectiveImplementingAfterContentInit implements AfterContentInit {
|
||||||
afterContentInit() {}
|
ngAfterContentInit() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DirectiveImplementingAfterContentChecked implements AfterContentChecked {
|
class DirectiveImplementingAfterContentChecked implements AfterContentChecked {
|
||||||
afterContentChecked() {}
|
ngAfterContentChecked() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DirectiveImplementingAfterViewInit implements AfterViewInit {
|
class DirectiveImplementingAfterViewInit implements AfterViewInit {
|
||||||
afterViewInit() {}
|
ngAfterViewInit() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DirectiveImplementingAfterViewChecked implements AfterViewChecked {
|
class DirectiveImplementingAfterViewChecked implements AfterViewChecked {
|
||||||
afterViewChecked() {}
|
ngAfterViewChecked() {}
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,8 @@ export function main() {
|
|||||||
describe('Create DirectiveMetadata', () => {
|
describe('Create DirectiveMetadata', () => {
|
||||||
describe('lifecycle', () => {
|
describe('lifecycle', () => {
|
||||||
|
|
||||||
describe("onChanges", () => {
|
describe("ngOnChanges", () => {
|
||||||
it("should be true when the directive has the onChanges method", () => {
|
it("should be true when the directive has the ngOnChanges method", () => {
|
||||||
expect(hasLifecycleHook(LifecycleHooks.OnChanges, DirectiveWithOnChangesMethod))
|
expect(hasLifecycleHook(LifecycleHooks.OnChanges, DirectiveWithOnChangesMethod))
|
||||||
.toBe(true);
|
.toBe(true);
|
||||||
});
|
});
|
||||||
@ -31,8 +31,8 @@ export function main() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("onDestroy", () => {
|
describe("ngOnDestroy", () => {
|
||||||
it("should be true when the directive has the onDestroy method", () => {
|
it("should be true when the directive has the ngOnDestroy method", () => {
|
||||||
expect(hasLifecycleHook(LifecycleHooks.OnDestroy, DirectiveWithOnDestroyMethod))
|
expect(hasLifecycleHook(LifecycleHooks.OnDestroy, DirectiveWithOnDestroyMethod))
|
||||||
.toBe(true);
|
.toBe(true);
|
||||||
});
|
});
|
||||||
@ -42,8 +42,8 @@ export function main() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("onInit", () => {
|
describe("ngOnInit", () => {
|
||||||
it("should be true when the directive has the onInit method", () => {
|
it("should be true when the directive has the ngOnInit method", () => {
|
||||||
expect(hasLifecycleHook(LifecycleHooks.OnInit, DirectiveWithOnInitMethod)).toBe(true);
|
expect(hasLifecycleHook(LifecycleHooks.OnInit, DirectiveWithOnInitMethod)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -52,8 +52,8 @@ export function main() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("doCheck", () => {
|
describe("ngDoCheck", () => {
|
||||||
it("should be true when the directive has the doCheck method", () => {
|
it("should be true when the directive has the ngDoCheck method", () => {
|
||||||
expect(hasLifecycleHook(LifecycleHooks.DoCheck, DirectiveWithOnCheckMethod)).toBe(true);
|
expect(hasLifecycleHook(LifecycleHooks.DoCheck, DirectiveWithOnCheckMethod)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -62,8 +62,8 @@ export function main() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("afterContentInit", () => {
|
describe("ngAfterContentInit", () => {
|
||||||
it("should be true when the directive has the afterContentInit method", () => {
|
it("should be true when the directive has the ngAfterContentInit method", () => {
|
||||||
expect(hasLifecycleHook(LifecycleHooks.AfterContentInit,
|
expect(hasLifecycleHook(LifecycleHooks.AfterContentInit,
|
||||||
DirectiveWithAfterContentInitMethod))
|
DirectiveWithAfterContentInitMethod))
|
||||||
.toBe(true);
|
.toBe(true);
|
||||||
@ -74,8 +74,8 @@ export function main() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("afterContentChecked", () => {
|
describe("ngAfterContentChecked", () => {
|
||||||
it("should be true when the directive has the afterContentChecked method", () => {
|
it("should be true when the directive has the ngAfterContentChecked method", () => {
|
||||||
expect(hasLifecycleHook(LifecycleHooks.AfterContentChecked,
|
expect(hasLifecycleHook(LifecycleHooks.AfterContentChecked,
|
||||||
DirectiveWithAfterContentCheckedMethod))
|
DirectiveWithAfterContentCheckedMethod))
|
||||||
.toBe(true);
|
.toBe(true);
|
||||||
@ -88,8 +88,8 @@ export function main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe("afterViewInit", () => {
|
describe("ngAfterViewInit", () => {
|
||||||
it("should be true when the directive has the afterViewInit method", () => {
|
it("should be true when the directive has the ngAfterViewInit method", () => {
|
||||||
expect(hasLifecycleHook(LifecycleHooks.AfterViewInit, DirectiveWithAfterViewInitMethod))
|
expect(hasLifecycleHook(LifecycleHooks.AfterViewInit, DirectiveWithAfterViewInitMethod))
|
||||||
.toBe(true);
|
.toBe(true);
|
||||||
});
|
});
|
||||||
@ -99,8 +99,8 @@ export function main() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("afterViewChecked", () => {
|
describe("ngAfterViewChecked", () => {
|
||||||
it("should be true when the directive has the afterViewChecked method", () => {
|
it("should be true when the directive has the ngAfterViewChecked method", () => {
|
||||||
expect(hasLifecycleHook(LifecycleHooks.AfterViewChecked,
|
expect(hasLifecycleHook(LifecycleHooks.AfterViewChecked,
|
||||||
DirectiveWithAfterViewCheckedMethod))
|
DirectiveWithAfterViewCheckedMethod))
|
||||||
.toBe(true);
|
.toBe(true);
|
||||||
@ -117,33 +117,33 @@ export function main() {
|
|||||||
class DirectiveNoHooks {}
|
class DirectiveNoHooks {}
|
||||||
|
|
||||||
class DirectiveWithOnChangesMethod {
|
class DirectiveWithOnChangesMethod {
|
||||||
onChanges(_) {}
|
ngOnChanges(_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DirectiveWithOnInitMethod {
|
class DirectiveWithOnInitMethod {
|
||||||
onInit() {}
|
ngOnInit() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DirectiveWithOnCheckMethod {
|
class DirectiveWithOnCheckMethod {
|
||||||
doCheck() {}
|
ngDoCheck() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DirectiveWithOnDestroyMethod {
|
class DirectiveWithOnDestroyMethod {
|
||||||
onDestroy() {}
|
ngOnDestroy() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DirectiveWithAfterContentInitMethod {
|
class DirectiveWithAfterContentInitMethod {
|
||||||
afterContentInit() {}
|
ngAfterContentInit() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DirectiveWithAfterContentCheckedMethod {
|
class DirectiveWithAfterContentCheckedMethod {
|
||||||
afterContentChecked() {}
|
ngAfterContentChecked() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DirectiveWithAfterViewInitMethod {
|
class DirectiveWithAfterViewInitMethod {
|
||||||
afterViewInit() {}
|
ngAfterViewInit() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DirectiveWithAfterViewCheckedMethod {
|
class DirectiveWithAfterViewCheckedMethod {
|
||||||
afterViewChecked() {}
|
ngAfterViewChecked() {}
|
||||||
}
|
}
|
||||||
|
@ -283,7 +283,7 @@ class DynamicallyCreatedCmp implements OnDestroy {
|
|||||||
this.dynamicallyCreatedComponentService = a;
|
this.dynamicallyCreatedComponentService = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
onDestroy() { this.destroyed = true; }
|
ngOnDestroy() { this.destroyed = true; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({selector: 'dummy'})
|
@Component({selector: 'dummy'})
|
||||||
|
@ -218,11 +218,11 @@ class B_Needs_A {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class DirectiveWithDestroy implements OnDestroy {
|
class DirectiveWithDestroy implements OnDestroy {
|
||||||
onDestroyCounter: number;
|
ngOnDestroyCounter: number;
|
||||||
|
|
||||||
constructor() { this.onDestroyCounter = 0; }
|
constructor() { this.ngOnDestroyCounter = 0; }
|
||||||
|
|
||||||
onDestroy() { this.onDestroyCounter++; }
|
ngOnDestroy() { this.ngOnDestroyCounter++; }
|
||||||
}
|
}
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
@ -823,14 +823,14 @@ export function main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("lifecycle", () => {
|
describe("lifecycle", () => {
|
||||||
it("should call onDestroy on directives subscribed to this event", () => {
|
it("should call ngOnDestroy on directives subscribed to this event", () => {
|
||||||
var inj = injector(ListWrapper.concat(
|
var inj = injector(ListWrapper.concat(
|
||||||
[DirectiveProvider.createFromType(DirectiveWithDestroy,
|
[DirectiveProvider.createFromType(DirectiveWithDestroy,
|
||||||
new DirectiveMetadata())],
|
new DirectiveMetadata())],
|
||||||
extraProviders));
|
extraProviders));
|
||||||
var destroy = inj.get(DirectiveWithDestroy);
|
var destroy = inj.get(DirectiveWithDestroy);
|
||||||
inj.dehydrate();
|
inj.dehydrate();
|
||||||
expect(destroy.onDestroyCounter).toBe(1);
|
expect(destroy.ngOnDestroyCounter).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should work with services", () => {
|
it("should work with services", () => {
|
||||||
@ -956,7 +956,7 @@ export function main() {
|
|||||||
false, preBuildObjects);
|
false, preBuildObjects);
|
||||||
|
|
||||||
addInj(dummyView, inj);
|
addInj(dummyView, inj);
|
||||||
inj.afterContentChecked();
|
inj.ngAfterContentChecked();
|
||||||
|
|
||||||
expectDirectives(inj.get(NeedsQuery).query, CountingDirective, [0]);
|
expectDirectives(inj.get(NeedsQuery).query, CountingDirective, [0]);
|
||||||
});
|
});
|
||||||
@ -969,7 +969,7 @@ export function main() {
|
|||||||
false, preBuiltObjects);
|
false, preBuiltObjects);
|
||||||
addInj(dummyView, inj);
|
addInj(dummyView, inj);
|
||||||
|
|
||||||
inj.afterContentChecked();
|
inj.ngAfterContentChecked();
|
||||||
|
|
||||||
expect(inj.get(NeedsTemplateRefQuery).query.first).toBe(preBuiltObjects.templateRef);
|
expect(inj.get(NeedsTemplateRefQuery).query.first).toBe(preBuiltObjects.templateRef);
|
||||||
});
|
});
|
||||||
@ -985,7 +985,7 @@ export function main() {
|
|||||||
false, preBuildObjects, null, dirVariableBindings);
|
false, preBuildObjects, null, dirVariableBindings);
|
||||||
|
|
||||||
addInj(dummyView, inj);
|
addInj(dummyView, inj);
|
||||||
inj.afterContentChecked();
|
inj.ngAfterContentChecked();
|
||||||
|
|
||||||
expect(inj.get(NeedsQueryByVarBindings).query.first).toBe(preBuildObjects.elementRef);
|
expect(inj.get(NeedsQueryByVarBindings).query.first).toBe(preBuildObjects.elementRef);
|
||||||
});
|
});
|
||||||
@ -1003,7 +1003,7 @@ export function main() {
|
|||||||
false, preBuildObjects, null, dirVariableBindings);
|
false, preBuildObjects, null, dirVariableBindings);
|
||||||
|
|
||||||
addInj(dummyView, inj);
|
addInj(dummyView, inj);
|
||||||
inj.afterContentChecked();
|
inj.ngAfterContentChecked();
|
||||||
|
|
||||||
// NeedsQueryByVarBindings queries "one,two", so SimpleDirective should be before NeedsDirective
|
// NeedsQueryByVarBindings queries "one,two", so SimpleDirective should be before NeedsDirective
|
||||||
expect(inj.get(NeedsQueryByVarBindings).query.first).toBeAnInstanceOf(SimpleDirective);
|
expect(inj.get(NeedsQueryByVarBindings).query.first).toBeAnInstanceOf(SimpleDirective);
|
||||||
@ -1022,7 +1022,7 @@ export function main() {
|
|||||||
|
|
||||||
addInj(dummyView, parent);
|
addInj(dummyView, parent);
|
||||||
addInj(dummyView, child);
|
addInj(dummyView, child);
|
||||||
parent.afterContentChecked();
|
parent.ngAfterContentChecked();
|
||||||
|
|
||||||
expectDirectives(parent.get(NeedsQuery).query, CountingDirective, [0, 1]);
|
expectDirectives(parent.get(NeedsQuery).query, CountingDirective, [0, 1]);
|
||||||
});
|
});
|
||||||
|
@ -275,7 +275,7 @@ class OnChangeComponent implements OnChanges {
|
|||||||
String prop;
|
String prop;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onChanges(Map changes) {
|
void ngOnChanges(Map changes) {
|
||||||
this.changes = changes;
|
this.changes = changes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -305,5 +305,5 @@ class DirectiveLoggingChecks implements DoCheck {
|
|||||||
|
|
||||||
DirectiveLoggingChecks(this.log);
|
DirectiveLoggingChecks(this.log);
|
||||||
|
|
||||||
doCheck() => log.add("check");
|
ngDoCheck() => log.add("check");
|
||||||
}
|
}
|
||||||
|
@ -680,7 +680,7 @@ class NeedsContentChildren implements AfterContentInit {
|
|||||||
@ContentChildren(TextDirective) textDirChildren: QueryList<TextDirective>;
|
@ContentChildren(TextDirective) textDirChildren: QueryList<TextDirective>;
|
||||||
numberOfChildrenAfterContentInit: number;
|
numberOfChildrenAfterContentInit: number;
|
||||||
|
|
||||||
afterContentInit() { this.numberOfChildrenAfterContentInit = this.textDirChildren.length; }
|
ngAfterContentInit() { this.numberOfChildrenAfterContentInit = this.textDirChildren.length; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({selector: 'needs-view-children'})
|
@Component({selector: 'needs-view-children'})
|
||||||
@ -689,7 +689,7 @@ class NeedsViewChildren implements AfterViewInit {
|
|||||||
@ViewChildren(TextDirective) textDirChildren: QueryList<TextDirective>;
|
@ViewChildren(TextDirective) textDirChildren: QueryList<TextDirective>;
|
||||||
numberOfChildrenAfterViewInit: number;
|
numberOfChildrenAfterViewInit: number;
|
||||||
|
|
||||||
afterViewInit() { this.numberOfChildrenAfterViewInit = this.textDirChildren.length; }
|
ngAfterViewInit() { this.numberOfChildrenAfterViewInit = this.textDirChildren.length; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({selector: 'needs-content-child'})
|
@Component({selector: 'needs-content-child'})
|
||||||
@ -706,9 +706,9 @@ class NeedsContentChild implements AfterContentInit, AfterContentChecked {
|
|||||||
get child() { return this._child; }
|
get child() { return this._child; }
|
||||||
log = [];
|
log = [];
|
||||||
|
|
||||||
afterContentInit() { this.log.push(["init", isPresent(this.child) ? this.child.text : null]); }
|
ngAfterContentInit() { this.log.push(["init", isPresent(this.child) ? this.child.text : null]); }
|
||||||
|
|
||||||
afterContentChecked() {
|
ngAfterContentChecked() {
|
||||||
this.log.push(["check", isPresent(this.child) ? this.child.text : null]);
|
this.log.push(["check", isPresent(this.child) ? this.child.text : null]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -734,9 +734,9 @@ class NeedsViewChild implements AfterViewInit,
|
|||||||
get child() { return this._child; }
|
get child() { return this._child; }
|
||||||
log = [];
|
log = [];
|
||||||
|
|
||||||
afterViewInit() { this.log.push(["init", isPresent(this.child) ? this.child.text : null]); }
|
ngAfterViewInit() { this.log.push(["init", isPresent(this.child) ? this.child.text : null]); }
|
||||||
|
|
||||||
afterViewChecked() { this.log.push(["check", isPresent(this.child) ? this.child.text : null]); }
|
ngAfterViewChecked() { this.log.push(["check", isPresent(this.child) ? this.child.text : null]); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ class HelloOnDestroyTickCmp implements OnDestroy {
|
|||||||
appRef: ApplicationRef;
|
appRef: ApplicationRef;
|
||||||
constructor(@Inject(ApplicationRef) appRef) { this.appRef = appRef; }
|
constructor(@Inject(ApplicationRef) appRef) { this.appRef = appRef; }
|
||||||
|
|
||||||
onDestroy(): void { this.appRef.tick(); }
|
ngOnDestroy(): void { this.appRef.tick(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ArrayLogger {
|
class _ArrayLogger {
|
||||||
|
@ -858,9 +858,9 @@ var NG_ALL = [
|
|||||||
'NG_VALUE_ACCESSOR',
|
'NG_VALUE_ACCESSOR',
|
||||||
'NG_ASYNC_VALIDATORS',
|
'NG_ASYNC_VALIDATORS',
|
||||||
'NgClass',
|
'NgClass',
|
||||||
'NgClass.doCheck()',
|
'NgClass.ngDoCheck()',
|
||||||
'NgClass.initialClasses=',
|
'NgClass.initialClasses=',
|
||||||
'NgClass.onDestroy()',
|
'NgClass.ngOnDestroy()',
|
||||||
'NgClass.rawClass=',
|
'NgClass.rawClass=',
|
||||||
'NgControl',
|
'NgControl',
|
||||||
'NgControl.control',
|
'NgControl.control',
|
||||||
@ -885,8 +885,8 @@ var NG_ALL = [
|
|||||||
'NgControlGroup.formDirective',
|
'NgControlGroup.formDirective',
|
||||||
'NgControlGroup.name',
|
'NgControlGroup.name',
|
||||||
'NgControlGroup.name=',
|
'NgControlGroup.name=',
|
||||||
'NgControlGroup.onDestroy()',
|
'NgControlGroup.ngOnDestroy()',
|
||||||
'NgControlGroup.onInit()',
|
'NgControlGroup.ngOnInit()',
|
||||||
'NgControlGroup.path',
|
'NgControlGroup.path',
|
||||||
'NgControlGroup.pristine',
|
'NgControlGroup.pristine',
|
||||||
'NgControlGroup.touched',
|
'NgControlGroup.touched',
|
||||||
@ -911,8 +911,8 @@ var NG_ALL = [
|
|||||||
'NgControlName.model=',
|
'NgControlName.model=',
|
||||||
'NgControlName.name',
|
'NgControlName.name',
|
||||||
'NgControlName.name=',
|
'NgControlName.name=',
|
||||||
'NgControlName.onChanges()',
|
'NgControlName.ngOnChanges()',
|
||||||
'NgControlName.onDestroy()',
|
'NgControlName.ngOnDestroy()',
|
||||||
'NgControlName.path',
|
'NgControlName.path',
|
||||||
'NgControlName.pristine',
|
'NgControlName.pristine',
|
||||||
'NgControlName.touched',
|
'NgControlName.touched',
|
||||||
@ -929,7 +929,7 @@ var NG_ALL = [
|
|||||||
'NgControlName.viewModel=',
|
'NgControlName.viewModel=',
|
||||||
'NgControlName.viewToModelUpdate()',
|
'NgControlName.viewToModelUpdate()',
|
||||||
'NgFor',
|
'NgFor',
|
||||||
'NgFor.doCheck()',
|
'NgFor.ngDoCheck()',
|
||||||
'NgFor.ngForOf=',
|
'NgFor.ngForOf=',
|
||||||
'NgFor.ngForTemplate=',
|
'NgFor.ngForTemplate=',
|
||||||
'NgForm',
|
'NgForm',
|
||||||
@ -968,7 +968,7 @@ var NG_ALL = [
|
|||||||
'NgFormControl.model=',
|
'NgFormControl.model=',
|
||||||
'NgFormControl.name',
|
'NgFormControl.name',
|
||||||
'NgFormControl.name=',
|
'NgFormControl.name=',
|
||||||
'NgFormControl.onChanges()',
|
'NgFormControl.ngOnChanges()',
|
||||||
'NgFormControl.path',
|
'NgFormControl.path',
|
||||||
'NgFormControl.pristine',
|
'NgFormControl.pristine',
|
||||||
'NgFormControl.touched',
|
'NgFormControl.touched',
|
||||||
@ -1001,7 +1001,7 @@ var NG_ALL = [
|
|||||||
'NgFormModel.name=',
|
'NgFormModel.name=',
|
||||||
'NgFormModel.ngSubmit',
|
'NgFormModel.ngSubmit',
|
||||||
'NgFormModel.ngSubmit=',
|
'NgFormModel.ngSubmit=',
|
||||||
'NgFormModel.onChanges()',
|
'NgFormModel.ngOnChanges()',
|
||||||
'NgFormModel.onSubmit()',
|
'NgFormModel.onSubmit()',
|
||||||
'NgFormModel.path',
|
'NgFormModel.path',
|
||||||
'NgFormModel.pristine',
|
'NgFormModel.pristine',
|
||||||
@ -1022,7 +1022,7 @@ var NG_ALL = [
|
|||||||
'NgModel.model=',
|
'NgModel.model=',
|
||||||
'NgModel.name',
|
'NgModel.name',
|
||||||
'NgModel.name=',
|
'NgModel.name=',
|
||||||
'NgModel.onChanges()',
|
'NgModel.ngOnChanges()',
|
||||||
'NgModel.path',
|
'NgModel.path',
|
||||||
'NgModel.pristine',
|
'NgModel.pristine',
|
||||||
'NgModel.touched',
|
'NgModel.touched',
|
||||||
@ -1040,7 +1040,7 @@ var NG_ALL = [
|
|||||||
'NgModel.viewToModelUpdate()',
|
'NgModel.viewToModelUpdate()',
|
||||||
'NgSelectOption',
|
'NgSelectOption',
|
||||||
'NgStyle',
|
'NgStyle',
|
||||||
'NgStyle.doCheck()',
|
'NgStyle.ngDoCheck()',
|
||||||
'NgStyle.rawStyle=',
|
'NgStyle.rawStyle=',
|
||||||
'NgSwitch',
|
'NgSwitch',
|
||||||
'NgSwitch.ngSwitch=',
|
'NgSwitch.ngSwitch=',
|
||||||
|
@ -274,7 +274,7 @@ class AppWithViewChildren implements AfterViewInit {
|
|||||||
|
|
||||||
constructor(public router: Router, public location: LocationStrategy) {}
|
constructor(public router: Router, public location: LocationStrategy) {}
|
||||||
|
|
||||||
afterViewInit() { this.helloCmp.message = 'Ahoy'; }
|
ngAfterViewInit() { this.helloCmp.message = 'Ahoy'; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -69,7 +69,7 @@ export function main() {
|
|||||||
eventBus = new EventEmitter();
|
eventBus = new EventEmitter();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should call the onActivate hook', inject([AsyncTestCompleter], (async) => {
|
it('should call the routerOnActivate hook', inject([AsyncTestCompleter], (async) => {
|
||||||
compile(tcb)
|
compile(tcb)
|
||||||
.then((rtc) => {fixture = rtc})
|
.then((rtc) => {fixture = rtc})
|
||||||
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
|
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
|
||||||
@ -82,7 +82,7 @@ export function main() {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should wait for a parent component\'s onActivate hook to resolve before calling its child\'s',
|
it('should wait for a parent component\'s routerOnActivate hook to resolve before calling its child\'s',
|
||||||
inject([AsyncTestCompleter], (async) => {
|
inject([AsyncTestCompleter], (async) => {
|
||||||
compile(tcb)
|
compile(tcb)
|
||||||
.then((rtc) => {fixture = rtc})
|
.then((rtc) => {fixture = rtc})
|
||||||
@ -106,7 +106,7 @@ export function main() {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should call the onDeactivate hook', inject([AsyncTestCompleter], (async) => {
|
it('should call the routerOnDeactivate hook', inject([AsyncTestCompleter], (async) => {
|
||||||
compile(tcb)
|
compile(tcb)
|
||||||
.then((rtc) => {fixture = rtc})
|
.then((rtc) => {fixture = rtc})
|
||||||
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
|
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
|
||||||
@ -120,7 +120,7 @@ export function main() {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should wait for a child component\'s onDeactivate hook to resolve before calling its parent\'s',
|
it('should wait for a child component\'s routerOnDeactivate hook to resolve before calling its parent\'s',
|
||||||
inject([AsyncTestCompleter], (async) => {
|
inject([AsyncTestCompleter], (async) => {
|
||||||
compile(tcb)
|
compile(tcb)
|
||||||
.then((rtc) => {fixture = rtc})
|
.then((rtc) => {fixture = rtc})
|
||||||
@ -146,7 +146,7 @@ export function main() {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should reuse a component when the canReuse hook returns true',
|
it('should reuse a component when the routerCanReuse hook returns true',
|
||||||
inject([AsyncTestCompleter], (async) => {
|
inject([AsyncTestCompleter], (async) => {
|
||||||
compile(tcb)
|
compile(tcb)
|
||||||
.then((rtc) => {fixture = rtc})
|
.then((rtc) => {fixture = rtc})
|
||||||
@ -169,7 +169,7 @@ export function main() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('should not reuse a component when the canReuse hook returns false',
|
it('should not reuse a component when the routerCanReuse hook returns false',
|
||||||
inject([AsyncTestCompleter], (async) => {
|
inject([AsyncTestCompleter], (async) => {
|
||||||
compile(tcb)
|
compile(tcb)
|
||||||
.then((rtc) => {fixture = rtc})
|
.then((rtc) => {fixture = rtc})
|
||||||
@ -192,34 +192,35 @@ export function main() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('should navigate when canActivate returns true', inject([AsyncTestCompleter], (async) => {
|
it('should navigate when routerCanActivate returns true',
|
||||||
compile(tcb)
|
|
||||||
.then((rtc) => {fixture = rtc})
|
|
||||||
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
|
|
||||||
.then((_) => {
|
|
||||||
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
|
|
||||||
if (ev.startsWith('canActivate')) {
|
|
||||||
completer.resolve(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
rtr.navigateByUrl('/can-activate/a')
|
|
||||||
.then((_) => {
|
|
||||||
fixture.detectChanges();
|
|
||||||
expect(fixture.debugElement.nativeElement).toHaveText('canActivate {A}');
|
|
||||||
expect(log).toEqual(['canActivate: null -> /can-activate']);
|
|
||||||
async.done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should not navigate when canActivate returns false',
|
|
||||||
inject([AsyncTestCompleter], (async) => {
|
inject([AsyncTestCompleter], (async) => {
|
||||||
compile(tcb)
|
compile(tcb)
|
||||||
.then((rtc) => {fixture = rtc})
|
.then((rtc) => {fixture = rtc})
|
||||||
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
|
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
|
||||||
.then((_) => {
|
.then((_) => {
|
||||||
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
|
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
|
||||||
if (ev.startsWith('canActivate')) {
|
if (ev.startsWith('routerCanActivate')) {
|
||||||
|
completer.resolve(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
rtr.navigateByUrl('/can-activate/a')
|
||||||
|
.then((_) => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(fixture.debugElement.nativeElement).toHaveText('routerCanActivate {A}');
|
||||||
|
expect(log).toEqual(['routerCanActivate: null -> /can-activate']);
|
||||||
|
async.done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should not navigate when routerCanActivate returns false',
|
||||||
|
inject([AsyncTestCompleter], (async) => {
|
||||||
|
compile(tcb)
|
||||||
|
.then((rtc) => {fixture = rtc})
|
||||||
|
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
|
||||||
|
.then((_) => {
|
||||||
|
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
|
||||||
|
if (ev.startsWith('routerCanActivate')) {
|
||||||
completer.resolve(false);
|
completer.resolve(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -227,13 +228,13 @@ export function main() {
|
|||||||
.then((_) => {
|
.then((_) => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(fixture.debugElement.nativeElement).toHaveText('');
|
expect(fixture.debugElement.nativeElement).toHaveText('');
|
||||||
expect(log).toEqual(['canActivate: null -> /can-activate']);
|
expect(log).toEqual(['routerCanActivate: null -> /can-activate']);
|
||||||
async.done();
|
async.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should navigate away when canDeactivate returns true',
|
it('should navigate away when routerCanDeactivate returns true',
|
||||||
inject([AsyncTestCompleter], (async) => {
|
inject([AsyncTestCompleter], (async) => {
|
||||||
compile(tcb)
|
compile(tcb)
|
||||||
.then((rtc) => {fixture = rtc})
|
.then((rtc) => {fixture = rtc})
|
||||||
@ -241,11 +242,11 @@ export function main() {
|
|||||||
.then((_) => rtr.navigateByUrl('/can-deactivate/a'))
|
.then((_) => rtr.navigateByUrl('/can-deactivate/a'))
|
||||||
.then((_) => {
|
.then((_) => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(fixture.debugElement.nativeElement).toHaveText('canDeactivate {A}');
|
expect(fixture.debugElement.nativeElement).toHaveText('routerCanDeactivate {A}');
|
||||||
expect(log).toEqual([]);
|
expect(log).toEqual([]);
|
||||||
|
|
||||||
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
|
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
|
||||||
if (ev.startsWith('canDeactivate')) {
|
if (ev.startsWith('routerCanDeactivate')) {
|
||||||
completer.resolve(true);
|
completer.resolve(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -253,13 +254,13 @@ export function main() {
|
|||||||
rtr.navigateByUrl('/a').then((_) => {
|
rtr.navigateByUrl('/a').then((_) => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(fixture.debugElement.nativeElement).toHaveText('A');
|
expect(fixture.debugElement.nativeElement).toHaveText('A');
|
||||||
expect(log).toEqual(['canDeactivate: /can-deactivate -> /a']);
|
expect(log).toEqual(['routerCanDeactivate: /can-deactivate -> /a']);
|
||||||
async.done();
|
async.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should not navigate away when canDeactivate returns false',
|
it('should not navigate away when routerCanDeactivate returns false',
|
||||||
inject([AsyncTestCompleter], (async) => {
|
inject([AsyncTestCompleter], (async) => {
|
||||||
compile(tcb)
|
compile(tcb)
|
||||||
.then((rtc) => {fixture = rtc})
|
.then((rtc) => {fixture = rtc})
|
||||||
@ -267,19 +268,19 @@ export function main() {
|
|||||||
.then((_) => rtr.navigateByUrl('/can-deactivate/a'))
|
.then((_) => rtr.navigateByUrl('/can-deactivate/a'))
|
||||||
.then((_) => {
|
.then((_) => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(fixture.debugElement.nativeElement).toHaveText('canDeactivate {A}');
|
expect(fixture.debugElement.nativeElement).toHaveText('routerCanDeactivate {A}');
|
||||||
expect(log).toEqual([]);
|
expect(log).toEqual([]);
|
||||||
|
|
||||||
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
|
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
|
||||||
if (ev.startsWith('canDeactivate')) {
|
if (ev.startsWith('routerCanDeactivate')) {
|
||||||
completer.resolve(false);
|
completer.resolve(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
rtr.navigateByUrl('/a').then((_) => {
|
rtr.navigateByUrl('/a').then((_) => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(fixture.debugElement.nativeElement).toHaveText('canDeactivate {A}');
|
expect(fixture.debugElement.nativeElement).toHaveText('routerCanDeactivate {A}');
|
||||||
expect(log).toEqual(['canDeactivate: /can-deactivate -> /a']);
|
expect(log).toEqual(['routerCanDeactivate: /can-deactivate -> /a']);
|
||||||
async.done();
|
async.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -294,10 +295,10 @@ export function main() {
|
|||||||
.then((_) => rtr.navigateByUrl('/activation-hooks/child'))
|
.then((_) => rtr.navigateByUrl('/activation-hooks/child'))
|
||||||
.then((_) => {
|
.then((_) => {
|
||||||
expect(log).toEqual([
|
expect(log).toEqual([
|
||||||
'canActivate child: null -> /child',
|
'routerCanActivate child: null -> /child',
|
||||||
'canActivate parent: null -> /activation-hooks',
|
'routerCanActivate parent: null -> /activation-hooks',
|
||||||
'onActivate parent: null -> /activation-hooks',
|
'routerOnActivate parent: null -> /activation-hooks',
|
||||||
'onActivate child: null -> /child'
|
'routerOnActivate child: null -> /child'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
log = [];
|
log = [];
|
||||||
@ -305,10 +306,10 @@ export function main() {
|
|||||||
})
|
})
|
||||||
.then((_) => {
|
.then((_) => {
|
||||||
expect(log).toEqual([
|
expect(log).toEqual([
|
||||||
'canDeactivate parent: /activation-hooks -> /a',
|
'routerCanDeactivate parent: /activation-hooks -> /a',
|
||||||
'canDeactivate child: /child -> null',
|
'routerCanDeactivate child: /child -> null',
|
||||||
'onDeactivate child: /child -> null',
|
'routerOnDeactivate child: /child -> null',
|
||||||
'onDeactivate parent: /activation-hooks -> /a'
|
'routerOnDeactivate parent: /activation-hooks -> /a'
|
||||||
]);
|
]);
|
||||||
async.done();
|
async.done();
|
||||||
});
|
});
|
||||||
@ -320,11 +321,13 @@ export function main() {
|
|||||||
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
|
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
|
||||||
.then((_) => rtr.navigateByUrl('/reuse-hooks/1'))
|
.then((_) => rtr.navigateByUrl('/reuse-hooks/1'))
|
||||||
.then((_) => {
|
.then((_) => {
|
||||||
expect(log).toEqual(
|
expect(log).toEqual([
|
||||||
['canActivate: null -> /reuse-hooks/1', 'onActivate: null -> /reuse-hooks/1']);
|
'routerCanActivate: null -> /reuse-hooks/1',
|
||||||
|
'routerOnActivate: null -> /reuse-hooks/1'
|
||||||
|
]);
|
||||||
|
|
||||||
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
|
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
|
||||||
if (ev.startsWith('canReuse')) {
|
if (ev.startsWith('routerCanReuse')) {
|
||||||
completer.resolve(true);
|
completer.resolve(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -335,8 +338,8 @@ export function main() {
|
|||||||
})
|
})
|
||||||
.then((_) => {
|
.then((_) => {
|
||||||
expect(log).toEqual([
|
expect(log).toEqual([
|
||||||
'canReuse: /reuse-hooks/1 -> /reuse-hooks/2',
|
'routerCanReuse: /reuse-hooks/1 -> /reuse-hooks/2',
|
||||||
'onReuse: /reuse-hooks/1 -> /reuse-hooks/2'
|
'routerOnReuse: /reuse-hooks/1 -> /reuse-hooks/2'
|
||||||
]);
|
]);
|
||||||
async.done();
|
async.done();
|
||||||
});
|
});
|
||||||
@ -347,11 +350,13 @@ export function main() {
|
|||||||
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
|
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
|
||||||
.then((_) => rtr.navigateByUrl('/reuse-hooks/1'))
|
.then((_) => rtr.navigateByUrl('/reuse-hooks/1'))
|
||||||
.then((_) => {
|
.then((_) => {
|
||||||
expect(log).toEqual(
|
expect(log).toEqual([
|
||||||
['canActivate: null -> /reuse-hooks/1', 'onActivate: null -> /reuse-hooks/1']);
|
'routerCanActivate: null -> /reuse-hooks/1',
|
||||||
|
'routerOnActivate: null -> /reuse-hooks/1'
|
||||||
|
]);
|
||||||
|
|
||||||
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
|
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
|
||||||
if (ev.startsWith('canReuse')) {
|
if (ev.startsWith('routerCanReuse')) {
|
||||||
completer.resolve(false);
|
completer.resolve(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -361,11 +366,11 @@ export function main() {
|
|||||||
})
|
})
|
||||||
.then((_) => {
|
.then((_) => {
|
||||||
expect(log).toEqual([
|
expect(log).toEqual([
|
||||||
'canReuse: /reuse-hooks/1 -> /reuse-hooks/2',
|
'routerCanReuse: /reuse-hooks/1 -> /reuse-hooks/2',
|
||||||
'canActivate: /reuse-hooks/1 -> /reuse-hooks/2',
|
'routerCanActivate: /reuse-hooks/1 -> /reuse-hooks/2',
|
||||||
'canDeactivate: /reuse-hooks/1 -> /reuse-hooks/2',
|
'routerCanDeactivate: /reuse-hooks/1 -> /reuse-hooks/2',
|
||||||
'onDeactivate: /reuse-hooks/1 -> /reuse-hooks/2',
|
'routerOnDeactivate: /reuse-hooks/1 -> /reuse-hooks/2',
|
||||||
'onActivate: /reuse-hooks/1 -> /reuse-hooks/2'
|
'routerOnActivate: /reuse-hooks/1 -> /reuse-hooks/2'
|
||||||
]);
|
]);
|
||||||
async.done();
|
async.done();
|
||||||
});
|
});
|
||||||
@ -393,7 +398,7 @@ function logHook(name: string, next: ComponentInstruction, prev: ComponentInstru
|
|||||||
|
|
||||||
@Component({selector: 'activate-cmp', template: 'activate cmp'})
|
@Component({selector: 'activate-cmp', template: 'activate cmp'})
|
||||||
class ActivateCmp implements OnActivate {
|
class ActivateCmp implements OnActivate {
|
||||||
onActivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
routerOnActivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||||
logHook('activate', next, prev);
|
logHook('activate', next, prev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -405,7 +410,7 @@ class ActivateCmp implements OnActivate {
|
|||||||
})
|
})
|
||||||
@RouteConfig([new Route({path: '/child-activate', component: ActivateCmp})])
|
@RouteConfig([new Route({path: '/child-activate', component: ActivateCmp})])
|
||||||
class ParentActivateCmp implements OnActivate {
|
class ParentActivateCmp implements OnActivate {
|
||||||
onActivate(next: ComponentInstruction, prev: ComponentInstruction): Promise<any> {
|
routerOnActivate(next: ComponentInstruction, prev: ComponentInstruction): Promise<any> {
|
||||||
completer = PromiseWrapper.completer();
|
completer = PromiseWrapper.completer();
|
||||||
logHook('parent activate', next, prev);
|
logHook('parent activate', next, prev);
|
||||||
return completer.promise;
|
return completer.promise;
|
||||||
@ -414,14 +419,14 @@ class ParentActivateCmp implements OnActivate {
|
|||||||
|
|
||||||
@Component({selector: 'deactivate-cmp', template: 'deactivate cmp'})
|
@Component({selector: 'deactivate-cmp', template: 'deactivate cmp'})
|
||||||
class DeactivateCmp implements OnDeactivate {
|
class DeactivateCmp implements OnDeactivate {
|
||||||
onDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
routerOnDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||||
logHook('deactivate', next, prev);
|
logHook('deactivate', next, prev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({selector: 'deactivate-cmp', template: 'deactivate cmp'})
|
@Component({selector: 'deactivate-cmp', template: 'deactivate cmp'})
|
||||||
class WaitDeactivateCmp implements OnDeactivate {
|
class WaitDeactivateCmp implements OnDeactivate {
|
||||||
onDeactivate(next: ComponentInstruction, prev: ComponentInstruction): Promise<any> {
|
routerOnDeactivate(next: ComponentInstruction, prev: ComponentInstruction): Promise<any> {
|
||||||
completer = PromiseWrapper.completer();
|
completer = PromiseWrapper.completer();
|
||||||
logHook('deactivate', next, prev);
|
logHook('deactivate', next, prev);
|
||||||
return completer.promise;
|
return completer.promise;
|
||||||
@ -435,7 +440,7 @@ class WaitDeactivateCmp implements OnDeactivate {
|
|||||||
})
|
})
|
||||||
@RouteConfig([new Route({path: '/child-deactivate', component: WaitDeactivateCmp})])
|
@RouteConfig([new Route({path: '/child-deactivate', component: WaitDeactivateCmp})])
|
||||||
class ParentDeactivateCmp implements OnDeactivate {
|
class ParentDeactivateCmp implements OnDeactivate {
|
||||||
onDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
routerOnDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||||
logHook('parent deactivate', next, prev);
|
logHook('parent deactivate', next, prev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -449,8 +454,10 @@ class ParentDeactivateCmp implements OnDeactivate {
|
|||||||
class ReuseCmp implements OnReuse,
|
class ReuseCmp implements OnReuse,
|
||||||
CanReuse {
|
CanReuse {
|
||||||
constructor() { cmpInstanceCount += 1; }
|
constructor() { cmpInstanceCount += 1; }
|
||||||
canReuse(next: ComponentInstruction, prev: ComponentInstruction) { return true; }
|
routerCanReuse(next: ComponentInstruction, prev: ComponentInstruction) { return true; }
|
||||||
onReuse(next: ComponentInstruction, prev: ComponentInstruction) { logHook('reuse', next, prev); }
|
routerOnReuse(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||||
|
logHook('reuse', next, prev);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -462,58 +469,61 @@ class ReuseCmp implements OnReuse,
|
|||||||
class NeverReuseCmp implements OnReuse,
|
class NeverReuseCmp implements OnReuse,
|
||||||
CanReuse {
|
CanReuse {
|
||||||
constructor() { cmpInstanceCount += 1; }
|
constructor() { cmpInstanceCount += 1; }
|
||||||
canReuse(next: ComponentInstruction, prev: ComponentInstruction) { return false; }
|
routerCanReuse(next: ComponentInstruction, prev: ComponentInstruction) { return false; }
|
||||||
onReuse(next: ComponentInstruction, prev: ComponentInstruction) { logHook('reuse', next, prev); }
|
routerOnReuse(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||||
|
logHook('reuse', next, prev);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'can-activate-cmp',
|
selector: 'can-activate-cmp',
|
||||||
template: `canActivate {<router-outlet></router-outlet>}`,
|
template: `routerCanActivate {<router-outlet></router-outlet>}`,
|
||||||
directives: [RouterOutlet]
|
directives: [RouterOutlet]
|
||||||
})
|
})
|
||||||
@RouteConfig([new Route({path: '/a', component: A}), new Route({path: '/b', component: B})])
|
@RouteConfig([new Route({path: '/a', component: A}), new Route({path: '/b', component: B})])
|
||||||
@CanActivate(CanActivateCmp.canActivate)
|
@CanActivate(CanActivateCmp.routerCanActivate)
|
||||||
class CanActivateCmp {
|
class CanActivateCmp {
|
||||||
static canActivate(next: ComponentInstruction, prev: ComponentInstruction): Promise<boolean> {
|
static routerCanActivate(next: ComponentInstruction,
|
||||||
|
prev: ComponentInstruction): Promise<boolean> {
|
||||||
completer = PromiseWrapper.completer();
|
completer = PromiseWrapper.completer();
|
||||||
logHook('canActivate', next, prev);
|
logHook('routerCanActivate', next, prev);
|
||||||
return completer.promise;
|
return completer.promise;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'can-deactivate-cmp',
|
selector: 'can-deactivate-cmp',
|
||||||
template: `canDeactivate {<router-outlet></router-outlet>}`,
|
template: `routerCanDeactivate {<router-outlet></router-outlet>}`,
|
||||||
directives: [RouterOutlet]
|
directives: [RouterOutlet]
|
||||||
})
|
})
|
||||||
@RouteConfig([new Route({path: '/a', component: A}), new Route({path: '/b', component: B})])
|
@RouteConfig([new Route({path: '/a', component: A}), new Route({path: '/b', component: B})])
|
||||||
class CanDeactivateCmp implements CanDeactivate {
|
class CanDeactivateCmp implements CanDeactivate {
|
||||||
canDeactivate(next: ComponentInstruction, prev: ComponentInstruction): Promise<boolean> {
|
routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction): Promise<boolean> {
|
||||||
completer = PromiseWrapper.completer();
|
completer = PromiseWrapper.completer();
|
||||||
logHook('canDeactivate', next, prev);
|
logHook('routerCanDeactivate', next, prev);
|
||||||
return completer.promise;
|
return completer.promise;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({selector: 'all-hooks-child-cmp', template: `child`})
|
@Component({selector: 'all-hooks-child-cmp', template: `child`})
|
||||||
@CanActivate(AllHooksChildCmp.canActivate)
|
@CanActivate(AllHooksChildCmp.routerCanActivate)
|
||||||
class AllHooksChildCmp implements CanDeactivate, OnDeactivate, OnActivate {
|
class AllHooksChildCmp implements CanDeactivate, OnDeactivate, OnActivate {
|
||||||
canDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||||
logHook('canDeactivate child', next, prev);
|
logHook('routerCanDeactivate child', next, prev);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
onDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
routerOnDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||||
logHook('onDeactivate child', next, prev);
|
logHook('routerOnDeactivate child', next, prev);
|
||||||
}
|
}
|
||||||
|
|
||||||
static canActivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
static routerCanActivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||||
logHook('canActivate child', next, prev);
|
logHook('routerCanActivate child', next, prev);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
onActivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
routerOnActivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||||
logHook('onActivate child', next, prev);
|
logHook('routerOnActivate child', next, prev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -523,57 +533,57 @@ class AllHooksChildCmp implements CanDeactivate, OnDeactivate, OnActivate {
|
|||||||
directives: [RouterOutlet]
|
directives: [RouterOutlet]
|
||||||
})
|
})
|
||||||
@RouteConfig([new Route({path: '/child', component: AllHooksChildCmp})])
|
@RouteConfig([new Route({path: '/child', component: AllHooksChildCmp})])
|
||||||
@CanActivate(AllHooksParentCmp.canActivate)
|
@CanActivate(AllHooksParentCmp.routerCanActivate)
|
||||||
class AllHooksParentCmp implements CanDeactivate,
|
class AllHooksParentCmp implements CanDeactivate,
|
||||||
OnDeactivate, OnActivate {
|
OnDeactivate, OnActivate {
|
||||||
canDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||||
logHook('canDeactivate parent', next, prev);
|
logHook('routerCanDeactivate parent', next, prev);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
onDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
routerOnDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||||
logHook('onDeactivate parent', next, prev);
|
logHook('routerOnDeactivate parent', next, prev);
|
||||||
}
|
}
|
||||||
|
|
||||||
static canActivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
static routerCanActivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||||
logHook('canActivate parent', next, prev);
|
logHook('routerCanActivate parent', next, prev);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
onActivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
routerOnActivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||||
logHook('onActivate parent', next, prev);
|
logHook('routerOnActivate parent', next, prev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({selector: 'reuse-hooks-cmp', template: 'reuse hooks cmp'})
|
@Component({selector: 'reuse-hooks-cmp', template: 'reuse hooks cmp'})
|
||||||
@CanActivate(ReuseHooksCmp.canActivate)
|
@CanActivate(ReuseHooksCmp.routerCanActivate)
|
||||||
class ReuseHooksCmp implements OnActivate, OnReuse, OnDeactivate, CanReuse, CanDeactivate {
|
class ReuseHooksCmp implements OnActivate, OnReuse, OnDeactivate, CanReuse, CanDeactivate {
|
||||||
canReuse(next: ComponentInstruction, prev: ComponentInstruction): Promise<any> {
|
routerCanReuse(next: ComponentInstruction, prev: ComponentInstruction): Promise<any> {
|
||||||
completer = PromiseWrapper.completer();
|
completer = PromiseWrapper.completer();
|
||||||
logHook('canReuse', next, prev);
|
logHook('routerCanReuse', next, prev);
|
||||||
return completer.promise;
|
return completer.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
onReuse(next: ComponentInstruction, prev: ComponentInstruction) {
|
routerOnReuse(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||||
logHook('onReuse', next, prev);
|
logHook('routerOnReuse', next, prev);
|
||||||
}
|
}
|
||||||
|
|
||||||
canDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||||
logHook('canDeactivate', next, prev);
|
logHook('routerCanDeactivate', next, prev);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
onDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
routerOnDeactivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||||
logHook('onDeactivate', next, prev);
|
logHook('routerOnDeactivate', next, prev);
|
||||||
}
|
}
|
||||||
|
|
||||||
static canActivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
static routerCanActivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||||
logHook('canActivate', next, prev);
|
logHook('routerCanActivate', next, prev);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
onActivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
routerOnActivate(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||||
logHook('onActivate', next, prev);
|
logHook('routerOnActivate', next, prev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,8 +238,8 @@ class DummyParentComp {
|
|||||||
function makeDummyOutlet() {
|
function makeDummyOutlet() {
|
||||||
var ref = new SpyRouterOutlet();
|
var ref = new SpyRouterOutlet();
|
||||||
ref.spy('canActivate').andCallFake((_) => PromiseWrapper.resolve(true));
|
ref.spy('canActivate').andCallFake((_) => PromiseWrapper.resolve(true));
|
||||||
ref.spy('canReuse').andCallFake((_) => PromiseWrapper.resolve(false));
|
ref.spy('routerCanReuse').andCallFake((_) => PromiseWrapper.resolve(false));
|
||||||
ref.spy('canDeactivate').andCallFake((_) => PromiseWrapper.resolve(true));
|
ref.spy('routerCanDeactivate').andCallFake((_) => PromiseWrapper.resolve(true));
|
||||||
ref.spy('activate').andCallFake((_) => PromiseWrapper.resolve(true));
|
ref.spy('activate').andCallFake((_) => PromiseWrapper.resolve(true));
|
||||||
return ref;
|
return ref;
|
||||||
}
|
}
|
||||||
|
@ -131,11 +131,11 @@ export function main() {
|
|||||||
template: "ignore: {{ignore}}; " +
|
template: "ignore: {{ignore}}; " +
|
||||||
"literal: {{literal}}; interpolate: {{interpolate}}; " +
|
"literal: {{literal}}; interpolate: {{interpolate}}; " +
|
||||||
"oneWayA: {{oneWayA}}; oneWayB: {{oneWayB}}; " +
|
"oneWayA: {{oneWayA}}; oneWayB: {{oneWayB}}; " +
|
||||||
"twoWayA: {{twoWayA}}; twoWayB: {{twoWayB}}; ({{onChangesCount}})"
|
"twoWayA: {{twoWayA}}; twoWayB: {{twoWayB}}; ({{ngOnChangesCount}})"
|
||||||
})
|
})
|
||||||
.Class({
|
.Class({
|
||||||
constructor: function() {
|
constructor: function() {
|
||||||
this.onChangesCount = 0;
|
this.ngOnChangesCount = 0;
|
||||||
this.ignore = '-';
|
this.ignore = '-';
|
||||||
this.literal = '?';
|
this.literal = '?';
|
||||||
this.interpolate = '?';
|
this.interpolate = '?';
|
||||||
@ -148,7 +148,7 @@ export function main() {
|
|||||||
this.twoWayAEmitter = new EventEmitter();
|
this.twoWayAEmitter = new EventEmitter();
|
||||||
this.twoWayBEmitter = new EventEmitter();
|
this.twoWayBEmitter = new EventEmitter();
|
||||||
},
|
},
|
||||||
onChanges: function(changes) {
|
ngOnChanges: function(changes) {
|
||||||
var assert = (prop, value) => {
|
var assert = (prop, value) => {
|
||||||
if (this[prop] != value) {
|
if (this[prop] != value) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@ -168,7 +168,7 @@ export function main() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (this.onChangesCount++) {
|
switch (this.ngOnChangesCount++) {
|
||||||
case 0:
|
case 0:
|
||||||
assert('ignore', '-');
|
assert('ignore', '-');
|
||||||
assertChange('literal', 'Text');
|
assertChange('literal', 'Text');
|
||||||
|
@ -85,7 +85,7 @@ export class MdAnchor extends MdButton implements OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Invoked when a change is detected. */
|
/** Invoked when a change is detected. */
|
||||||
onChanges(_) {
|
ngOnChanges(_) {
|
||||||
// A disabled anchor should not be in the tab flow.
|
// A disabled anchor should not be in the tab flow.
|
||||||
this.tabIndex = this.disabled ? -1 : 0;
|
this.tabIndex = this.disabled ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ export class MdGridList implements AfterContentChecked {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
afterContentChecked() {
|
ngAfterContentChecked() {
|
||||||
this.layoutTiles();
|
this.layoutTiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,7 +267,7 @@ export class MdGridTile implements OnDestroy,
|
|||||||
* Change handler invoked when bindings are resolved or when bindings have changed.
|
* Change handler invoked when bindings are resolved or when bindings have changed.
|
||||||
* Notifies grid-list that a re-layout is required.
|
* Notifies grid-list that a re-layout is required.
|
||||||
*/
|
*/
|
||||||
onChanges(_) {
|
ngOnChanges(_) {
|
||||||
if (!this.isRegisteredWithGridList) {
|
if (!this.isRegisteredWithGridList) {
|
||||||
this.gridList.addTile(this);
|
this.gridList.addTile(this);
|
||||||
this.isRegisteredWithGridList = true;
|
this.isRegisteredWithGridList = true;
|
||||||
@ -277,7 +277,7 @@ export class MdGridTile implements OnDestroy,
|
|||||||
/**
|
/**
|
||||||
* Destructor function. Deregisters this tile from the containing grid-list.
|
* Destructor function. Deregisters this tile from the containing grid-list.
|
||||||
*/
|
*/
|
||||||
onDestroy() {
|
ngOnDestroy() {
|
||||||
this.gridList.removeTile(this);
|
this.gridList.removeTile(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ export class MdInputContainer implements AfterContentChecked {
|
|||||||
this.inputHasFocus = false;
|
this.inputHasFocus = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
afterContentChecked() {
|
ngAfterContentChecked() {
|
||||||
// Enforce that this directive actually contains a text input.
|
// Enforce that this directive actually contains a text input.
|
||||||
if (this._input == null) {
|
if (this._input == null) {
|
||||||
throw 'No <input> or <textarea> found inside of <md-input-container>';
|
throw 'No <input> or <textarea> found inside of <md-input-container>';
|
||||||
|
@ -60,7 +60,7 @@ export class MdProgressLinear implements OnChanges {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onChanges(_) {
|
ngOnChanges(_) {
|
||||||
// If the mode does not use a value, or if there is no value, do nothing.
|
// If the mode does not use a value, or if there is no value, do nothing.
|
||||||
if (this.mode == ProgressMode.QUERY || this.mode == ProgressMode.INDETERMINATE ||
|
if (this.mode == ProgressMode.QUERY || this.mode == ProgressMode.INDETERMINATE ||
|
||||||
isBlank(this.value)) {
|
isBlank(this.value)) {
|
||||||
|
@ -102,7 +102,7 @@ export class MdRadioGroup implements OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Change handler invoked when bindings are resolved or when bindings have changed. */
|
/** Change handler invoked when bindings are resolved or when bindings have changed. */
|
||||||
onChanges(_) {
|
ngOnChanges(_) {
|
||||||
// If the component has a disabled attribute with no value, it will set disabled = ''.
|
// If the component has a disabled attribute with no value, it will set disabled = ''.
|
||||||
this.disabled = isPresent(this.disabled) && this.disabled !== false;
|
this.disabled = isPresent(this.disabled) && this.disabled !== false;
|
||||||
|
|
||||||
@ -263,7 +263,7 @@ export class MdRadioButton implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Change handler invoked when bindings are resolved or when bindings have changed. */
|
/** Change handler invoked when bindings are resolved or when bindings have changed. */
|
||||||
onInit() {
|
ngOnInit() {
|
||||||
if (isPresent(this.radioGroup)) {
|
if (isPresent(this.radioGroup)) {
|
||||||
this.name = this.radioGroup.getName();
|
this.name = this.radioGroup.getName();
|
||||||
}
|
}
|
||||||
|
@ -545,20 +545,20 @@ class _CodegenState {
|
|||||||
String _genDoCheck(ProtoRecord r) {
|
String _genDoCheck(ProtoRecord r) {
|
||||||
var br = r.bindingRecord;
|
var br = r.bindingRecord;
|
||||||
return 'if (!throwOnChange) '
|
return 'if (!throwOnChange) '
|
||||||
'${_names.getDirectiveName(br.directiveRecord.directiveIndex)}.doCheck();';
|
'${_names.getDirectiveName(br.directiveRecord.directiveIndex)}.ngDoCheck();';
|
||||||
}
|
}
|
||||||
|
|
||||||
String _genOnInit(ProtoRecord r) {
|
String _genOnInit(ProtoRecord r) {
|
||||||
var br = r.bindingRecord;
|
var br = r.bindingRecord;
|
||||||
return 'if (!throwOnChange && ${_names.getStateName()} == ${_genPrefix}$_STATE.NeverChecked) '
|
return 'if (!throwOnChange && ${_names.getStateName()} == ${_genPrefix}$_STATE.NeverChecked) '
|
||||||
'${_names.getDirectiveName(br.directiveRecord.directiveIndex)}.onInit();';
|
'${_names.getDirectiveName(br.directiveRecord.directiveIndex)}.ngOnInit();';
|
||||||
}
|
}
|
||||||
|
|
||||||
String _genOnChanges(ProtoRecord r) {
|
String _genOnChanges(ProtoRecord r) {
|
||||||
var br = r.bindingRecord;
|
var br = r.bindingRecord;
|
||||||
return 'if (!throwOnChange && $_CHANGES_LOCAL != null) '
|
return 'if (!throwOnChange && $_CHANGES_LOCAL != null) '
|
||||||
'${_names.getDirectiveName(br.directiveRecord.directiveIndex)}'
|
'${_names.getDirectiveName(br.directiveRecord.directiveIndex)}'
|
||||||
'.onChanges($_CHANGES_LOCAL);';
|
'.ngOnChanges($_CHANGES_LOCAL);';
|
||||||
}
|
}
|
||||||
|
|
||||||
String _genNotifyOnPushDetectors(ProtoRecord r) {
|
String _genNotifyOnPushDetectors(ProtoRecord r) {
|
||||||
|
Reference in New Issue
Block a user