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]];