From 6276a2cd55eba035b6d6fe859bff574514ce0b00 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Mon, 21 Dec 2015 21:35:57 +0200 Subject: [PATCH] Add destroy handler to BaseComponent --- lib/components/base.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/components/base.js b/lib/components/base.js index a4df8f35..e6e3ef81 100644 --- a/lib/components/base.js +++ b/lib/components/base.js @@ -1,5 +1,5 @@ 'use strict'; -import {Component, View, OnInit, ChangeDetectionStrategy} from 'angular2/core'; +import {Component, View, OnInit, OnDestroy, ChangeDetectionStrategy} from 'angular2/core'; import {CORE_DIRECTIVES, JsonPipe} from 'angular2/common'; import SchemaManager from '../utils/SchemaManager'; import JsonPointer from '../utils/JsonPointer'; @@ -41,7 +41,7 @@ export function RedocComponent(options) { selector: options.selector, inputs: inputs, outputs: options.outputs, - lifecycle: [OnInit], + lifecycle: [OnInit, OnDestroy], providers: options.providers, changeDetection: options.changeDetection || ChangeDetectionStrategy.Detached }); @@ -77,6 +77,10 @@ export class BaseComponent { this.init(); } + ngOnDestroy() { + this.destroy(); + } + /** * simple in-place schema dereferencing. Schema is already bundled so no need in global dereferencing. * TODO: doesn't support circular references @@ -151,5 +155,11 @@ export class BaseComponent { * @abstract */ init() {} + + /** + + Used to destroy component + * @abstract + */ + destroy() {} } BaseComponent.parameters = [[SchemaManager]];