NgbTab reloading components on tab chage

陌路散爱 提交于 2019-12-20 01:09:18

问题


I have 2 tabs and inside the tab content there is a component i developed. When ever I move from one tab to another and come back to the tab on which my developed component is place, it reloads and calls its lifecycle methods called which causing problem for me.

Is there a way to stop reloading the component on change of the tab.

HTML code :

<ngb-tabset>
    <ngb-tab title="xyz..." id="overview">
        <ng-template ngbTabContent>
            ...
            <sd-tags [existingTags]="tags" [somethingelse]="otherstuffs" [more]="morestuff"></sd-tags>
            ...
        </ng-template>
    </ngb-tab>
    <ngb-tab [title]="sothingesele" id="columns">
        <ng-template ngbTabContent>
            ...
        </ng-template>
    </ngb-tab>
</ngb-tabset>

When tab changed, the sd-tabs component reloads and what ever is processed, it comes to initial stage and causing problem.


回答1:


I guess you are looking for destroyOnHide input property on ngb-tabset:

<ngb-tabset [destroyOnHide]="false">
  ...
</ngb-tabset>

According to the docs

destroyOnHide

Default value: true

Whether the closed tabs should be hidden without destroying them

Plunker Example



来源:https://stackoverflow.com/questions/45641843/ngbtab-reloading-components-on-tab-chage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!