mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-21 04:53:58 +08:00
feat(changeDetection): detach Tabs when not active
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import {Component, Directive, Host, Inject, forwardRef, ElementRef, Compiler, AppViewManager, NgZone, Renderer, Type, ViewEncapsulation} from 'angular2/core';
|
import {Component, Directive, Host, Inject, forwardRef, ElementRef, Compiler, AppViewManager, NgZone, Renderer, Type, ViewEncapsulation, ChangeDetectorRef} from 'angular2/core';
|
||||||
import {EventEmitter, Input, Output} from 'angular2/core';
|
import {EventEmitter, Input, Output} from 'angular2/core';
|
||||||
|
|
||||||
import {IonicApp} from '../app/app';
|
import {IonicApp} from '../app/app';
|
||||||
@ -216,7 +216,8 @@ export class Tab extends NavController {
|
|||||||
compiler: Compiler,
|
compiler: Compiler,
|
||||||
viewManager: AppViewManager,
|
viewManager: AppViewManager,
|
||||||
zone: NgZone,
|
zone: NgZone,
|
||||||
renderer: Renderer
|
renderer: Renderer,
|
||||||
|
private _cd: ChangeDetectorRef
|
||||||
) {
|
) {
|
||||||
// A Tab is a NavController for its child pages
|
// A Tab is a NavController for its child pages
|
||||||
super(parentTabs, app, config, keyboard, elementRef, 'contents', compiler, viewManager, zone, renderer);
|
super(parentTabs, app, config, keyboard, elementRef, 'contents', compiler, viewManager, zone, renderer);
|
||||||
@ -296,6 +297,16 @@ export class Tab extends NavController {
|
|||||||
*/
|
*/
|
||||||
setSelected(isSelected: boolean) {
|
setSelected(isSelected: boolean) {
|
||||||
this.isSelected = isSelected;
|
this.isSelected = isSelected;
|
||||||
|
|
||||||
|
if (isSelected) {
|
||||||
|
// this is the selected tab, detect changes
|
||||||
|
this._cd.reattach();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// this tab is not selected, do not detect changes
|
||||||
|
this._cd.detach();
|
||||||
|
}
|
||||||
|
|
||||||
this.hideNavbars(!isSelected);
|
this.hideNavbars(!isSelected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user