From 22dbd6ad99ab2604aa97a1789582f89f3a4e59e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 15 Nov 2023 17:02:43 +0100 Subject: [PATCH] MOBILE-3947 core: Stop using ComponentFactoryResolver --- .../filter/displayh5p/services/handlers/displayh5p.ts | 9 ++------- .../components/dynamic-component/dynamic-component.ts | 5 +---- src/core/components/navbar-buttons/navbar-buttons.ts | 6 ++---- src/core/singletons/index.ts | 6 +++--- 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/addons/filter/displayh5p/services/handlers/displayh5p.ts b/src/addons/filter/displayh5p/services/handlers/displayh5p.ts index ae5ec4f2c..3949f2b15 100644 --- a/src/addons/filter/displayh5p/services/handlers/displayh5p.ts +++ b/src/addons/filter/displayh5p/services/handlers/displayh5p.ts @@ -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(factory); + const componentRef = viewContainerRef.createComponent(CoreH5PPlayerComponent); componentRef.instance.src = url; componentRef.instance.component = component; diff --git a/src/core/components/dynamic-component/dynamic-component.ts b/src/core/components/dynamic-component/dynamic-component.ts index 72876a368..82a8d4310 100644 --- a/src/core/components/dynamic-component/dynamic-component.ts +++ b/src/core/components/dynamic-component/dynamic-component.ts @@ -20,7 +20,6 @@ import { OnChanges, DoCheck, ViewContainerRef, - ComponentFactoryResolver, ComponentRef, KeyValueDiffers, SimpleChange, @@ -85,7 +84,6 @@ export class CoreDynamicComponent implements OnChanges, DoCheck protected lastComponent?: Type; constructor( - protected factoryResolver: ComponentFactoryResolver, differs: KeyValueDiffers, protected cdr: ChangeDetectorRef, protected element: ElementRef, @@ -172,8 +170,7 @@ export class CoreDynamicComponent 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) { diff --git a/src/core/components/navbar-buttons/navbar-buttons.ts b/src/core/components/navbar-buttons/navbar-buttons.ts index 662ce0cf8..b63f656c1 100644 --- a/src/core/components/navbar-buttons/navbar-buttons.ts +++ b/src/core/components/navbar-buttons/navbar-buttons.ts @@ -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(factory); + const componentRef = this.container.createComponent(CoreContextMenuComponent); this.createdMainContextMenuElement = componentRef.location.nativeElement; diff --git a/src/core/singletons/index.ts b/src/core/singletons/index.ts index 51df7f5f8..ae1a6f99e 100644 --- a/src/core/singletons/index.ts +++ b/src/core/singletons/index.ts @@ -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, '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); });