0

I have theHtmlString variable and bind as follow is correct:

<div [innerHTML]="theHtmlString">
</div>

But theHtmlString variable has contain some orther variable:

theHtmlString = "<input [(ngModel)]='value'/>";

How bind HTML for it?

2
  • 1
    what @GunterZochbauer said, and as a result, you'll need to use DynamicComponentLoader to implement this. Commented Apr 18, 2016 at 10:38
  • But i have not get data from dynamic component loader Commented Apr 18, 2016 at 10:49

2 Answers 2

3

Angular doesn't process HTML added this way. It doesn't resolve bindings nor instantiate components or directives. It's passed to the browser as-is.

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

2 Comments

So is it impossible to accomplish this?
I wouldn't say impossible, but not plain simple either ;-). You can create a component at runtime like explained in stackoverflow.com/questions/34784778/… and add this component instead. There is a ready-to-use library that makes it easier to dynamically create components (don't remember the name). Currently this is not compatible with AoT though.
2

You could use something like that in the template:

<div [innerHTML]="value + 'abc ...'">
</div>

Otherwise you can use curly brackets this way into your expression...

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.