mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-10 00:27:41 +08:00
refactor(nav): add initial support for url in general, add integration w/ ng-router
This commit is contained in:
@ -26,7 +26,7 @@ export class AngularComponentMounter {
|
||||
|
||||
const crf = componentResolveFactory ? componentResolveFactory : this.defaultCfr;
|
||||
|
||||
const mountingData = attachViewToDom(crf, parentElement, hostElement, componentToMount, injector, this.appRef, data, classesToAdd);
|
||||
const mountingData = this.attachViewToDomImpl(crf, parentElement, hostElement, componentToMount, injector, this.appRef, data, classesToAdd);
|
||||
resolve(mountingData);
|
||||
});
|
||||
});
|
||||
@ -41,43 +41,45 @@ export class AngularComponentMounter {
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
attachViewToDomImpl(crf: ComponentFactoryResolver, parentElement: HTMLElement, hostElement: HTMLElement, componentToMount: Type<any>, injector: Injector, appRef: ApplicationRef, data: any, classesToAdd: string[]): AngularMountingData {
|
||||
|
||||
export function removeViewFromDom(_parentElement: HTMLElement, childElement: HTMLElement) {
|
||||
const mountingData = elementToComponentRefMap.get(childElement);
|
||||
if (mountingData) {
|
||||
mountingData.componentRef.destroy();
|
||||
}
|
||||
}
|
||||
const componentProviders = ReflectiveInjector.resolve(getProviders(parentElement, data));
|
||||
const componentFactory = crf.resolveComponentFactory(componentToMount);
|
||||
if (!hostElement) {
|
||||
hostElement = document.createElement(componentFactory.selector);
|
||||
}
|
||||
|
||||
export function attachViewToDom(crf: ComponentFactoryResolver, parentElement: HTMLElement, hostElement: HTMLElement, componentToMount: Type<any>, injector: Injector, appRef: ApplicationRef, data: any, classesToAdd: string[]): AngularMountingData {
|
||||
const childInjector = ReflectiveInjector.fromResolvedProviders(componentProviders, injector);
|
||||
const componentRef = componentFactory.create(childInjector, [], hostElement);
|
||||
for (const clazz of classesToAdd) {
|
||||
hostElement.classList.add(clazz);
|
||||
}
|
||||
|
||||
const componentProviders = ReflectiveInjector.resolve(getProviders(parentElement, data));
|
||||
const componentFactory = crf.resolveComponentFactory(componentToMount);
|
||||
if (!hostElement) {
|
||||
hostElement = document.createElement(componentFactory.selector);
|
||||
}
|
||||
parentElement.appendChild(hostElement);
|
||||
|
||||
const childInjector = ReflectiveInjector.fromResolvedProviders(componentProviders, injector);
|
||||
const componentRef = componentFactory.create(childInjector, [], hostElement);
|
||||
for (const clazz of classesToAdd) {
|
||||
hostElement.classList.add(clazz);
|
||||
}
|
||||
appRef.attachView(componentRef.hostView);
|
||||
|
||||
parentElement.appendChild(hostElement);
|
||||
const mountingData = {
|
||||
component: componentToMount,
|
||||
componentFactory,
|
||||
childInjector,
|
||||
componentRef,
|
||||
instance: componentRef.instance,
|
||||
angularHostElement: componentRef.location.nativeElement,
|
||||
element: hostElement,
|
||||
data
|
||||
};
|
||||
|
||||
appRef.attachView(componentRef.hostView);
|
||||
elementToComponentRefMap.set(hostElement, mountingData);
|
||||
|
||||
const mountingData = {
|
||||
componentFactory,
|
||||
childInjector,
|
||||
componentRef,
|
||||
instance: componentRef.instance,
|
||||
angularHostElement: componentRef.location.nativeElement,
|
||||
element: hostElement,
|
||||
};
|
||||
return mountingData;
|
||||
}
|
||||
|
||||
elementToComponentRefMap.set(hostElement, mountingData);
|
||||
}
|
||||
|
||||
return mountingData;
|
||||
export function removeViewFromDom(_parentElement: HTMLElement, childElement: HTMLElement) {
|
||||
const mountingData = elementToComponentRefMap.get(childElement);
|
||||
if (mountingData) {
|
||||
mountingData.componentRef.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,9 +36,9 @@ export class ModalController implements FrameworkDelegate {
|
||||
});
|
||||
}
|
||||
|
||||
attachViewToDom(elementOrContainerToMountTo: HTMLElement, elementOrComponentToMount: Type<any>, _propsOrDataObj?: any, classesToAdd?: string[]): Promise<AngularMountingData> {
|
||||
attachViewToDom(elementOrContainerToMountTo: HTMLElement, elementOrComponentToMount: Type<any>, data?: any, classesToAdd?: string[]): Promise<AngularMountingData> {
|
||||
|
||||
return this.angularComponentMounter.attachViewToDom(elementOrContainerToMountTo, null, elementOrComponentToMount, this.componentResolveFactory, this.injector, _propsOrDataObj, classesToAdd);
|
||||
return this.angularComponentMounter.attachViewToDom(elementOrContainerToMountTo, null, elementOrComponentToMount, this.componentResolveFactory, this.injector, data, classesToAdd);
|
||||
}
|
||||
|
||||
removeViewFromDom(parentElement: HTMLElement, childElement: HTMLElement) {
|
||||
|
||||
@ -29,9 +29,16 @@ export class PopoverController implements FrameworkDelegate {
|
||||
return getPopoverProxy(opts);
|
||||
}
|
||||
|
||||
attachViewToDom(elementOrContainerToMountTo: HTMLElement, elementOrComponentToMount: Type<any>, _propsOrDataObj?: any, classesToAdd?: string[]): Promise<AngularMountingData> {
|
||||
dismiss(data?: any, role?: string, id?: number) {
|
||||
const popoverController = document.querySelector('ion-popover-controller');
|
||||
return (popoverController as any).componentOnReady().then(() => {
|
||||
return popoverController.dismiss(data, role, id);
|
||||
});
|
||||
}
|
||||
|
||||
attachViewToDom(elementOrContainerToMountTo: HTMLElement, elementOrComponentToMount: Type<any>, data?: any, classesToAdd?: string[]): Promise<AngularMountingData> {
|
||||
|
||||
return this.angularComponentMounter.attachViewToDom(elementOrContainerToMountTo, null, elementOrComponentToMount, this.componentResolveFactory, this.injector, _propsOrDataObj, classesToAdd);
|
||||
return this.angularComponentMounter.attachViewToDom(elementOrContainerToMountTo, null, elementOrComponentToMount, this.componentResolveFactory, this.injector, data, classesToAdd);
|
||||
}
|
||||
|
||||
removeViewFromDom(parentElement: HTMLElement, childElement: HTMLElement) {
|
||||
|
||||
Reference in New Issue
Block a user