feat(core): support ngOnDestroy on providers of a directive.

Such providers also become eager as they will be instantiated
anyways on destruction.
This commit is contained in:
Tobias Bosch
2016-08-02 01:37:42 -07:00
parent ff3b71f7b3
commit c161ed415d
10 changed files with 87 additions and 42 deletions

View File

@ -9,7 +9,7 @@
import {LifecycleHooks} from '../../core_private';
import {CompileDirectiveMetadata, CompilePipeMetadata} from '../compile_metadata';
import * as o from '../output/output_ast';
import {DirectiveAst} from '../template_parser/template_ast';
import {DirectiveAst, ProviderAst} from '../template_parser/template_ast';
import {CompileElement} from './compile_element';
import {CompileView} from './compile_view';
@ -77,12 +77,11 @@ export function bindDirectiveAfterViewLifecycleCallbacks(
}
}
export function bindDirectiveDestroyLifecycleCallbacks(
directiveMeta: CompileDirectiveMetadata, directiveInstance: o.Expression,
compileElement: CompileElement) {
export function bindInjectableDestroyLifecycleCallbacks(
provider: ProviderAst, directiveInstance: o.Expression, compileElement: CompileElement) {
var onDestroyMethod = compileElement.view.destroyMethod;
onDestroyMethod.resetDebugInfo(compileElement.nodeIndex, compileElement.sourceAst);
if (directiveMeta.type.lifecycleHooks.indexOf(LifecycleHooks.OnDestroy) !== -1) {
if (provider.lifecycleHooks.indexOf(LifecycleHooks.OnDestroy) !== -1) {
onDestroyMethod.addStmt(directiveInstance.callMethod('ngOnDestroy', []).toStmt());
}
}