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?

Nguyen
  • 425
  • 8
  • 18
  • 1
    what @GunterZochbauer said, and as a result, you'll need to use [`DynamicComponentLoader`](https://angular.io/docs/ts/latest/api/core/DynamicComponentLoader-class.html) to implement this. – drew moore Apr 18 '16 at 10:38
  • But i have not get data from dynamic component loader – Nguyen Apr 18 '16 at 10:49

2 Answers2

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.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • So is it impossible to accomplish this? – Emilio Weba Mar 15 '17 at 15:39
  • I wouldn't say impossible, but not plain simple either ;-). You can create a component at runtime like explained in http://stackoverflow.com/questions/34784778/equivalent-of-compile-in-angular-2/37044960#37044960 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. – Günter Zöchbauer Mar 15 '17 at 15:41
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...

Thierry Templier
  • 198,364
  • 44
  • 396
  • 360