diff --git a/lib/components/Redoc/redoc.ts b/lib/components/Redoc/redoc.ts index 8efcd4d7..33d3b638 100644 --- a/lib/components/Redoc/redoc.ts +++ b/lib/components/Redoc/redoc.ts @@ -5,6 +5,7 @@ import { ElementRef, Input, Component, OnInit, + OnDestroy, HostBinding } from '@angular/core'; @@ -26,7 +27,9 @@ import { LazyTasksService } from '../../shared/components/LazyFor/lazy-for'; export class Redoc extends BaseComponent implements OnInit { static _preOptions: any; - private element: any; + private element: HTMLElement; + private $parent: Element; + private $refElem: Element; error: any; specLoaded: boolean; @@ -53,6 +56,9 @@ export class Redoc extends BaseComponent implements OnInit { optionsMgr.options = Redoc._preOptions || {}; this.element = elementRef.nativeElement; + this.$parent = this.element.parentElement; + this.$refElem = this.element.nextElementSibling; + //parse options (top level component doesn't support inputs) optionsMgr.parseOptions( this.element ); let scrollParent = detectScollParent( this.element ); @@ -121,4 +127,9 @@ export class Redoc extends BaseComponent implements OnInit { } this.load(); } + + ngOnDestroy() { + let $clone = this.element.cloneNode(); + this.$parent.insertBefore($clone, this.$refElem); + } } diff --git a/lib/components/SideMenu/side-menu.ts b/lib/components/SideMenu/side-menu.ts index fd97c2cb..3a6bc0fc 100644 --- a/lib/components/SideMenu/side-menu.ts +++ b/lib/components/SideMenu/side-menu.ts @@ -1,6 +1,6 @@ 'use strict'; -import { Component, ElementRef, ChangeDetectorRef, OnInit } from '@angular/core'; +import { Component, ElementRef, ChangeDetectorRef, OnInit, OnDestroy } from '@angular/core'; //import { global } from '@angular/core/src/facade/lang'; import { trigger, state, animate, transition, style } from '@angular/core'; @@ -28,7 +28,7 @@ const global = window; ]) ], }) -export class SideMenu extends BaseComponent implements OnInit { +export class SideMenu extends BaseComponent implements OnInit, OnDestroy { activeCatCaption: string; activeItemCaption: string; categories: Array; @@ -123,6 +123,11 @@ export class SideMenu extends BaseComponent implements OnInit { destroy() { this.scrollService.unbind(); + this.menuService.destroy(); + } + + ngOnDestroy() { + this.destroy(); } ngOnInit() { diff --git a/lib/index.ts b/lib/index.ts index bb2fdc3a..163de55a 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -33,7 +33,6 @@ export function init(specUrl:string, options:any = {}) { moduleRef = appRef; console.log('ReDoc initialized!'); }).catch(err => { - //Redoc.displayError(err); throw err; }); }; diff --git a/lib/services/menu.service.ts b/lib/services/menu.service.ts index d470facb..bd32b9b5 100644 --- a/lib/services/menu.service.ts +++ b/lib/services/menu.service.ts @@ -1,5 +1,6 @@ 'use strict'; import { Injectable, EventEmitter } from '@angular/core'; +import { Subscription } from 'rxjs/Subscription'; import { BehaviorSubject } from 'rxjs/BehaviorSubject'; import { ScrollService, INVIEW_POSITION } from './scroll.service'; import { Hash } from './hash.service'; @@ -16,6 +17,8 @@ const CHANGE = { @Injectable() export class MenuService { + private _hashSubscription: Subscription; + changed: EventEmitter = new EventEmitter(); ready: BehaviorSubject = new BehaviorSubject(false); categories: Array; @@ -39,7 +42,7 @@ export class MenuService { //this.changeActive(CHANGE.INITIAL); - this.hash.value.subscribe((hash) => { + this._hashSubscription = this.hash.value.subscribe((hash) => { if (hash == undefined) return; this.setActiveByHash(hash); if (!this.tasks.empty) { @@ -228,4 +231,8 @@ export class MenuService { } this.activate(catIdx, methodIdx); } + + destroy() { + this._hashSubscription.unsubscribe(); + } }