mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-16 18:17:31 +08:00
refactor(angular): change how angular mounts a component, use the angular selector if possible
This commit is contained in:
@ -22,8 +22,7 @@ export class IonNavDelegate implements FrameworkDelegate {
|
|||||||
|
|
||||||
attachViewToDom(elementOrContainerToMountTo: HTMLIonNavElement, elementOrComponentToMount: Type<any>, _propsOrDataObj?: any, classesToAdd?: string[]): Promise<AngularMountingData> {
|
attachViewToDom(elementOrContainerToMountTo: HTMLIonNavElement, elementOrComponentToMount: Type<any>, _propsOrDataObj?: any, classesToAdd?: string[]): Promise<AngularMountingData> {
|
||||||
|
|
||||||
const hostElement = document.createElement('div');
|
return this.angularComponentMounter.attachViewToDom(elementOrContainerToMountTo, null, elementOrComponentToMount, this.componentResolveFactory, this.injector, _propsOrDataObj, classesToAdd);
|
||||||
return this.angularComponentMounter.attachViewToDom(elementOrContainerToMountTo, hostElement, elementOrComponentToMount, this.componentResolveFactory, this.injector, _propsOrDataObj, classesToAdd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
removeViewFromDom(_parentElement: HTMLElement, childElement: HTMLElement) {
|
removeViewFromDom(_parentElement: HTMLElement, childElement: HTMLElement) {
|
||||||
|
@ -54,6 +54,9 @@ export function attachViewToDom(crf: ComponentFactoryResolver, parentElement: HT
|
|||||||
|
|
||||||
const componentProviders = ReflectiveInjector.resolve(getProviders(parentElement, data));
|
const componentProviders = ReflectiveInjector.resolve(getProviders(parentElement, data));
|
||||||
const componentFactory = crf.resolveComponentFactory(componentToMount);
|
const componentFactory = crf.resolveComponentFactory(componentToMount);
|
||||||
|
if (!hostElement) {
|
||||||
|
hostElement = document.createElement(componentFactory.selector);
|
||||||
|
}
|
||||||
const childInjector = ReflectiveInjector.fromResolvedProviders(componentProviders, injector);
|
const childInjector = ReflectiveInjector.fromResolvedProviders(componentProviders, injector);
|
||||||
const componentRef = componentFactory.create(childInjector, [], hostElement);
|
const componentRef = componentFactory.create(childInjector, [], hostElement);
|
||||||
for (const clazz of classesToAdd) {
|
for (const clazz of classesToAdd) {
|
||||||
|
@ -31,8 +31,7 @@ export class ModalController implements FrameworkDelegate {
|
|||||||
|
|
||||||
attachViewToDom(elementOrContainerToMountTo: HTMLElement, elementOrComponentToMount: Type<any>, _propsOrDataObj?: any, classesToAdd?: string[]): Promise<AngularMountingData> {
|
attachViewToDom(elementOrContainerToMountTo: HTMLElement, elementOrComponentToMount: Type<any>, _propsOrDataObj?: any, classesToAdd?: string[]): Promise<AngularMountingData> {
|
||||||
|
|
||||||
const hostElement = document.createElement('div');
|
return this.angularComponentMounter.attachViewToDom(elementOrContainerToMountTo, null, elementOrComponentToMount, this.componentResolveFactory, this.injector, _propsOrDataObj, classesToAdd);
|
||||||
return this.angularComponentMounter.attachViewToDom(elementOrContainerToMountTo, hostElement, elementOrComponentToMount, this.componentResolveFactory, this.injector, _propsOrDataObj, classesToAdd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
removeViewFromDom(_parentElement: HTMLElement, childElement: HTMLElement) {
|
removeViewFromDom(_parentElement: HTMLElement, childElement: HTMLElement) {
|
||||||
|
@ -31,8 +31,7 @@ export class PopoverController implements FrameworkDelegate {
|
|||||||
|
|
||||||
attachViewToDom(elementOrContainerToMountTo: HTMLElement, elementOrComponentToMount: Type<any>, _propsOrDataObj?: any, classesToAdd?: string[]): Promise<AngularMountingData> {
|
attachViewToDom(elementOrContainerToMountTo: HTMLElement, elementOrComponentToMount: Type<any>, _propsOrDataObj?: any, classesToAdd?: string[]): Promise<AngularMountingData> {
|
||||||
|
|
||||||
const hostElement = document.createElement('div');
|
return this.angularComponentMounter.attachViewToDom(elementOrContainerToMountTo, null, elementOrComponentToMount, this.componentResolveFactory, this.injector, _propsOrDataObj, classesToAdd);
|
||||||
return this.angularComponentMounter.attachViewToDom(elementOrContainerToMountTo, hostElement, elementOrComponentToMount, this.componentResolveFactory, this.injector, _propsOrDataObj, classesToAdd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
removeViewFromDom(_parentElement: HTMLElement, childElement: HTMLElement) {
|
removeViewFromDom(_parentElement: HTMLElement, childElement: HTMLElement) {
|
||||||
|
Reference in New Issue
Block a user