Skip to content

Commit

Permalink
fix: remove deprecated ComponenetFactoryResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s committed Aug 15, 2022
1 parent f62cb13 commit 41524f3
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions projects/ngx-editor/src/lib/plugins/image-resize.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApplicationRef, ComponentFactoryResolver, ComponentRef, Injector } from '@angular/core';
import { ApplicationRef, ComponentRef, createComponent, Injector } from '@angular/core';
import { Node as ProseMirrorNode } from 'prosemirror-model';
import { NodeSelection, Plugin, PluginKey } from 'prosemirror-state';
import { EditorView, NodeView } from 'prosemirror-view';
Expand All @@ -19,20 +19,16 @@ class ImageRezieView implements NodeView {
updating = false;

constructor(node: ProseMirrorNode, view: EditorView, getPos: () => number, injector: Injector) {
const componentFactoryResolver = injector.get(ComponentFactoryResolver);
this.applicationRef = injector.get(ApplicationRef);

// Create the component and wire it up with the element
const factory = componentFactoryResolver.resolveComponentFactory(ImageViewComponent);
// create component ref
this.imageComponentRef = createComponent(ImageViewComponent, {
environmentInjector: this.applicationRef.injector,
});

this.imageComponentRef = factory.create(injector, []);
// Attach to the view so that the change detector knows to run
this.applicationRef.attachView(this.imageComponentRef.hostView);

// Possible alternate for deprecated ComponentFactoryResolver
// const viewContainerRef = injector.get(ViewContainerRef);
// this.imageComponentRef = viewContainerRef.createComponent(ImageViewComponent, { injector });

this.setNodeAttributes(node.attrs);
this.imageComponentRef.instance.view = view;

Expand Down

0 comments on commit 41524f3

Please sign in to comment.