mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 12:29:55 +08:00
refactor(modal): simplify component loading
This commit is contained in:
@ -54,34 +54,32 @@ export class ModalCmp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ionViewPreLoad() {
|
ionViewPreLoad() {
|
||||||
this._load(this._navParams.data.component);
|
const component = this._navParams.data.component;
|
||||||
}
|
if (!component) {
|
||||||
|
console.warn('modal\'s page was not defined');
|
||||||
/** @hidden */
|
return;
|
||||||
_load(component: any) {
|
|
||||||
if (component) {
|
|
||||||
|
|
||||||
let cfr = this.moduleLoader.getComponentFactoryResolver(component);
|
|
||||||
if (!cfr) {
|
|
||||||
cfr = this._cfr;
|
|
||||||
}
|
|
||||||
const componentFactory = cfr.resolveComponentFactory(component);
|
|
||||||
|
|
||||||
// ******** DOM WRITE ****************
|
|
||||||
const componentRef = this._viewport.createComponent(componentFactory, this._viewport.length, this._viewport.parentInjector, []);
|
|
||||||
|
|
||||||
this._setCssClass(componentRef, 'ion-page');
|
|
||||||
this._setCssClass(componentRef, 'show-page');
|
|
||||||
|
|
||||||
// Change the viewcontroller's instance to point the user provided page
|
|
||||||
// Lifecycle events will be sent to the new instance, instead of the modal's component
|
|
||||||
// we need to manually subscribe to them
|
|
||||||
this._viewCtrl._setInstance(componentRef.instance);
|
|
||||||
this._viewCtrl.willEnter.subscribe(this._viewWillEnter.bind(this));
|
|
||||||
this._viewCtrl.didLeave.subscribe(this._viewDidLeave.bind(this));
|
|
||||||
|
|
||||||
this._enabled = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let cfr = this.moduleLoader.getComponentFactoryResolver(component);
|
||||||
|
if (!cfr) {
|
||||||
|
cfr = this._cfr;
|
||||||
|
}
|
||||||
|
const componentFactory = cfr.resolveComponentFactory(component);
|
||||||
|
|
||||||
|
// ******** DOM WRITE ****************
|
||||||
|
const componentRef = this._viewport.createComponent(componentFactory, this._viewport.length, this._viewport.parentInjector, []);
|
||||||
|
|
||||||
|
this._setCssClass(componentRef, 'ion-page');
|
||||||
|
this._setCssClass(componentRef, 'show-page');
|
||||||
|
|
||||||
|
// Change the viewcontroller's instance to point the user provided page
|
||||||
|
// Lifecycle events will be sent to the new instance, instead of the modal's component
|
||||||
|
// we need to manually subscribe to them
|
||||||
|
this._viewCtrl._setInstance(componentRef.instance);
|
||||||
|
this._viewCtrl.willEnter.subscribe(this._viewWillEnter.bind(this));
|
||||||
|
this._viewCtrl.didLeave.subscribe(this._viewDidLeave.bind(this));
|
||||||
|
|
||||||
|
this._enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
_viewWillEnter() {
|
_viewWillEnter() {
|
||||||
@ -92,7 +90,6 @@ export class ModalCmp {
|
|||||||
this._gestureBlocker.unblock();
|
this._gestureBlocker.unblock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hidden */
|
|
||||||
_setCssClass(componentRef: any, className: string) {
|
_setCssClass(componentRef: any, className: string) {
|
||||||
this._renderer.setElementClass(componentRef.location.nativeElement, className, true);
|
this._renderer.setElementClass(componentRef.location.nativeElement, className, true);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user