mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-17 18:54:11 +08:00
fix(angular): lifecycles
This commit is contained in:
@ -2,6 +2,7 @@ import { Attribute, ChangeDetectorRef, ComponentFactoryResolver, ComponentRef, D
|
|||||||
import { ActivatedRoute, ChildrenOutletContexts, PRIMARY_OUTLET, Router } from '@angular/router';
|
import { ActivatedRoute, ChildrenOutletContexts, PRIMARY_OUTLET, Router } from '@angular/router';
|
||||||
import { StackController } from './router-controller';
|
import { StackController } from './router-controller';
|
||||||
import { NavController } from './ion-nav-controller';
|
import { NavController } from './ion-nav-controller';
|
||||||
|
import { bindLifecycleEvents } from '../providers/angular-delegate';
|
||||||
|
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: 'ion-router-outlet',
|
selector: 'ion-router-outlet',
|
||||||
@ -129,7 +130,9 @@ export class IonRouterOutlet implements OnDestroy, OnInit {
|
|||||||
const childContexts = this.parentContexts.getOrCreateContext(this.name).children;
|
const childContexts = this.parentContexts.getOrCreateContext(this.name).children;
|
||||||
|
|
||||||
const injector = new OutletInjector(activatedRoute, childContexts, this.location.injector);
|
const injector = new OutletInjector(activatedRoute, childContexts, this.location.injector);
|
||||||
this.activated = this.location.createComponent(factory, this.location.length, injector);
|
const cmp = this.activated = this.location.createComponent(factory, this.location.length, injector);
|
||||||
|
|
||||||
|
bindLifecycleEvents(cmp.instance, cmp.location.nativeElement);
|
||||||
|
|
||||||
// Calling `markForCheck` to make sure we will run the change detection when the
|
// Calling `markForCheck` to make sure we will run the change detection when the
|
||||||
// `RouterOutlet` is inside a `ChangeDetectionStrategy.OnPush` component.
|
// `RouterOutlet` is inside a `ChangeDetectionStrategy.OnPush` component.
|
||||||
|
@ -5,7 +5,7 @@ import {
|
|||||||
Injector,
|
Injector,
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
|
|
||||||
import { FrameworkDelegate } from '@ionic/core';
|
import { FrameworkDelegate, ViewLifecycle } from '@ionic/core';
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ -44,7 +44,7 @@ export class AngularFrameworkDelegate implements FrameworkDelegate {
|
|||||||
for (const clazz of cssClasses) {
|
for (const clazz of cssClasses) {
|
||||||
hostElement.classList.add(clazz);
|
hostElement.classList.add(clazz);
|
||||||
}
|
}
|
||||||
|
bindLifecycleEvents(componentRef.instance, hostElement);
|
||||||
container.appendChild(hostElement);
|
container.appendChild(hostElement);
|
||||||
|
|
||||||
this.appRef.attachView(componentRef.hostView);
|
this.appRef.attachView(componentRef.hostView);
|
||||||
@ -62,3 +62,20 @@ export class AngularFrameworkDelegate implements FrameworkDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const LIFECYCLES = [
|
||||||
|
ViewLifecycle.WillEnter,
|
||||||
|
ViewLifecycle.DidEnter,
|
||||||
|
ViewLifecycle.WillLeave,
|
||||||
|
ViewLifecycle.DidLeave,
|
||||||
|
ViewLifecycle.WillUnload
|
||||||
|
];
|
||||||
|
|
||||||
|
export function bindLifecycleEvents(instance: any, element: HTMLElement) {
|
||||||
|
LIFECYCLES.forEach(eventName => {
|
||||||
|
element.addEventListener(eventName, (ev: CustomEvent) => {
|
||||||
|
if (typeof instance[eventName] === 'function') {
|
||||||
|
instance[eventName](ev.detail);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
11942
core/package-lock.json
generated
11942
core/package-lock.json
generated
File diff suppressed because one or more lines are too long
1
core/src/index.d.ts
vendored
1
core/src/index.d.ts
vendored
@ -109,6 +109,7 @@ export * from './components';
|
|||||||
export { DomController, RafCallback } from './global/dom-controller';
|
export { DomController, RafCallback } from './global/dom-controller';
|
||||||
export { FrameworkDelegate } from './utils/framework-delegate';
|
export { FrameworkDelegate } from './utils/framework-delegate';
|
||||||
export { OverlayEventDetail } from './utils/overlays';
|
export { OverlayEventDetail } from './utils/overlays';
|
||||||
|
export * from './utils/transition';
|
||||||
|
|
||||||
export type ComponentRef = Function | HTMLElement | string;
|
export type ComponentRef = Function | HTMLElement | string;
|
||||||
export type ComponentProps = {[key: string]: any};
|
export type ComponentProps = {[key: string]: any};
|
||||||
|
Reference in New Issue
Block a user