MOBILE-3947 core: Stop using ComponentFactoryResolver

main
Pau Ferrer Ocaña 2023-11-15 17:02:43 +01:00 committed by Dani Palou
parent 33b0afd242
commit 22dbd6ad99
4 changed files with 8 additions and 18 deletions

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { Injectable, ViewContainerRef, ComponentFactoryResolver } from '@angular/core';
import { Injectable, ViewContainerRef } from '@angular/core';
import { CoreFilterDefaultHandler } from '@features/filter/services/handlers/default-filter';
import { CoreFilterFilter, CoreFilterFormatTextOptions } from '@features/filter/services/filter';
@ -32,10 +32,6 @@ export class AddonFilterDisplayH5PHandlerService extends CoreFilterDefaultHandle
protected template = document.createElement('template'); // A template element to convert HTML to element.
constructor(protected factoryResolver: ComponentFactoryResolver) {
super();
}
/**
* @inheritdoc
*/
@ -95,8 +91,7 @@ export class AddonFilterDisplayH5PHandlerService extends CoreFilterDefaultHandle
const url = placeholder.getAttribute('data-player-src') || '';
// Create the component to display the player.
const factory = this.factoryResolver.resolveComponentFactory(CoreH5PPlayerComponent);
const componentRef = viewContainerRef.createComponent<CoreH5PPlayerComponent>(factory);
const componentRef = viewContainerRef.createComponent<CoreH5PPlayerComponent>(CoreH5PPlayerComponent);
componentRef.instance.src = url;
componentRef.instance.component = component;

View File

@ -20,7 +20,6 @@ import {
OnChanges,
DoCheck,
ViewContainerRef,
ComponentFactoryResolver,
ComponentRef,
KeyValueDiffers,
SimpleChange,
@ -85,7 +84,6 @@ export class CoreDynamicComponent<ComponentClass> implements OnChanges, DoCheck
protected lastComponent?: Type<unknown>;
constructor(
protected factoryResolver: ComponentFactoryResolver,
differs: KeyValueDiffers,
protected cdr: ChangeDetectorRef,
protected element: ElementRef,
@ -172,8 +170,7 @@ export class CoreDynamicComponent<ComponentClass> implements OnChanges, DoCheck
} else {
try {
// Create the component and add it to the container.
const factory = this.factoryResolver.resolveComponentFactory(this.component);
const componentRef = this.container.createComponent(factory);
const componentRef = this.container.createComponent(this.component);
this.instance = componentRef.instance;
} catch (ex) {

View File

@ -20,7 +20,6 @@ import {
ElementRef,
ViewContainerRef,
ViewChild,
ComponentFactoryResolver,
} from '@angular/core';
import { CoreLogger } from '@singletons/logger';
import { CoreDomUtils } from '@services/utils/dom';
@ -78,7 +77,7 @@ export class CoreNavBarButtonsComponent implements OnInit, OnDestroy {
protected mergedContextMenu?: CoreContextMenuComponent;
protected createdMainContextMenuElement?: HTMLElement;
constructor(element: ElementRef, protected factoryResolver: ComponentFactoryResolver) {
constructor(element: ElementRef) {
this.element = element.nativeElement;
this.logger = CoreLogger.getInstance('CoreNavBarButtonsComponent');
@ -186,8 +185,7 @@ export class CoreNavBarButtonsComponent implements OnInit, OnDestroy {
* @returns Created component.
*/
protected createMainContextMenu(): CoreContextMenuComponent {
const factory = this.factoryResolver.resolveComponentFactory(CoreContextMenuComponent);
const componentRef = this.container.createComponent<CoreContextMenuComponent>(factory);
const componentRef = this.container.createComponent(CoreContextMenuComponent);
this.createdMainContextMenuElement = componentRef.location.nativeElement;

View File

@ -16,10 +16,10 @@ import {
AbstractType,
ApplicationInitStatus,
ApplicationRef,
ComponentFactoryResolver as ComponentFactoryResolverService,
Injector,
NgZone as NgZoneService,
Type,
EnvironmentInjector,
} from '@angular/core';
import { Router as RouterService } from '@angular/router';
import { HttpClient } from '@angular/common/http';
@ -206,7 +206,6 @@ export const Http = makeSingleton(HttpClient);
export const ActionSheetController = makeSingleton(ActionSheetControllerService);
export const AngularDelegate = makeSingleton(AngularDelegateService);
export const AlertController = makeSingleton(AlertControllerService);
export const ComponentFactoryResolver = makeSingleton(ComponentFactoryResolverService);
export const LoadingController = makeSingleton(LoadingControllerService);
export const ModalController = makeSingleton(ModalControllerService);
export const PopoverController = makeSingleton(PopoverControllerService);
@ -227,6 +226,7 @@ export const Translate: Omit<CoreSingletonProxy<TranslateService>, 'instant'> &
// Async singletons.
export const AngularFrameworkDelegate = asyncInstance(async () => {
const injector = await singletonsInjector;
const environmentInjector = await injector.get(EnvironmentInjector);
return AngularDelegate.create(ComponentFactoryResolver.instance, injector);
return AngularDelegate.create(environmentInjector, injector);
});