0

I am fetching part of the page from some service. How can I achieve that angular expression or router staff working as dynamic content?

Controller.ts

 variable = 'some text';
 dynamicContent ='
     {{variable}} 
     Or
     <a  [routerLink]="contact"]></a>';

View.html

<div>
     {{dynamicContent}}//plain text 
     <div [innerHtml]="dynamicContent"></div> //html without angular expressions
</div>

So innerHtml is close. It can build html but cannot understand angular 2 expressions. I found out ng-dynamic module but it also undesrstand only html. The best solution atm is html outlet that i found on some stack questions. But it is not supporting AOT...

user2771738
  • 913
  • 11
  • 31

2 Answers2

0

Angular never processes dynamic content, except stripping some security relevant stuff if not sanitizized. Angular bindings and components are only processed when added to a components template statically.

You can create a component dynamically where you put the dynamic content into them components template

See also Equivalent of $compile in Angular 2

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
0

You should write it like this:

dynamicContent = this.variable + ' Or <a href="#/contact"></a>';

Here is a plunker: https://plnkr.co/edit/EqJRUs3mGKwjnXzbuwAo?p=preview

sanyooh
  • 1,260
  • 2
  • 18
  • 31