refactor(nav): add initial support for url in general, add integration w/ ng-router

This commit is contained in:
Dan Bucholtz
2018-01-31 10:52:50 -06:00
committed by GitHub
parent e2b7f64296
commit ab2176b6ce
176 changed files with 17791 additions and 6779 deletions

View File

@ -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();
}
}

View File

@ -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) {

View File

@ -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) {