Angular 6 - Rendering of dynamic content

18 views
Skip to first unread message

Christoph Kind

unread,
Aug 17, 2018, 12:19:54 PM8/17/18
to Angular and AngularJS discussion
How can I get dynamicly added content to get rendered?

For example: 
var box = $('#content-box');
box.append( "<p>Test {{ binding }}</p>" );



{{ binding }} will not get rendered.


Any suggestions?

Regards
Chris

Sander Elias

unread,
Aug 17, 2018, 11:46:48 PM8/17/18
to Angular and AngularJS discussion
Hi Christoph,

While possible by manually invoking the compiler, it's not an easy thing to do. 
Can you give a sample of what it is you are trying to do, usually there is a simpler way to accomplish the same.

Regards
Sander

Zlatko Đurić

unread,
Aug 18, 2018, 2:58:52 AM8/18/18
to Angular and AngularJS discussion
If you just want to render some hand-written HTML, use DomSanitizer (https://angular.io/api/platform-browser/DomSanitizer, here is an example: https://stackblitz.com/edit/angular-safe-unsafe-html) in your component. If you want more dynamic behavior with template binding etc, you can either try to build out this component dynamically (e.g. like in this answer on SO: https://stackoverflow.com/a/48028892/162070). Hope that helps.

Zlatko

Reply all
Reply to author
Forward
0 new messages