0

We are trying to pass inputs to an angular web component. To make system robust, from api we will get two values

  1. Script URL
  2. Selector name ( below example component we are getting from db as well )

So we are able to add script dynamically and then added selector name by using createElement of renderer2. But now we are stuck as we want to pass inputs to that component like

<component [data]="'Hello'"></component>

so question is how we can add angular input tags in element which is added in DOM by using

renderer.createElement

Is it possible to pass or should change logic to add element ?
Main point is both javascript location and selector is dynamic.

Thanks in advance

2
  • Have a look at the docs, there are setAttribute / setProperty methods: angular.io/api/core/Renderer2 Commented Jul 30, 2020 at 16:53
  • Oh, ok, from another answer I'm not quite sure if property binding is actually possible with this. Commented Jul 30, 2020 at 17:02

2 Answers 2

0

You should create your component via ComponentFactory like here (https://stackoverflow.com/a/50429222/7255496) and set component inputs manually.

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

1 Comment

In my situation we dont have component class or anything as its dynamically loaded from third party. So we can't have instace of component
0

According to this link : https://angular.io/guide/elements#typings-for-custom-elements

I think you can just specify element.InputName = InputValue;

So In your case it should be

const comp = document.createElement('component');
comp.data = 'hello';

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.