0

I'm using third party js tool, which inject some html code into the page, as far as I know it using runOutsideAngular.
I need to find one of the element of that generated content and inject my component into it. What I'm trying to do is

const element=document.getElementById("page");

const factory = this.componentFactoryResolver.resolveComponentFactory(MyComponent);
const ref = factory.create(this.injector, [],element);
this.applicationRef.attachView(ref.hostView);

But this code doesn't work because that "page" element isn't tracked by angular. (If I inject my component into any tag defined in angular template it works)

How can I achieve this?

1 Answer 1

0

Thanks. I finally figure out.

so basically what i had to do is to run everything inside the angular zone.

    this.ngZone.run(() => {
      const element=document.getElementById("page");
      const factory = this.resolver.resolveComponentFactory(PdfRedactionComponent);
      const ref = factory.create(this.injector, [], element);
      this.app.attachView(ref.hostView);
    });

And now everything is working as I expected.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.