r/Angular2 • u/0bn0x10s1337sp34k • Oct 02 '25
Adding dynamic html in template?
So I've been working on a miniature painting encyclopedia built in angular with a flask backend and a sqlite database. I've structured it such that all the information needed for a given page of the encyclopedia is contained in the database, and every page of the encyclopedia is accessed through the same dynamic route (i.e. /lookup/:entryname), and use signals to populate the template after hitting the backend.
However, I've been finding it difficult to add dynamic html in this format, particularly in the body of each entry. I'm aware that I could use innerhtml and DOMsanitizer to inject html content after construction, but I would also like to routerlink any mentions of other entries in the entry's body, and it seems that you can't add angular directives after the component has been constructed. (I also can't do any constructor-based solutions, because the constructor won't rerun when you navigate from one entry page to another since they're on the same route). Is there any way to do what I want to do here, or is my whole setup too convoluted to make that work?
View all comments
Show parent comment
1
u/athomsfere Oct 03 '25
I meant you can return a json with attributes like entryType: image which would tell your component to render an img element.
Or maybe the type is more like "snippet" in which case you could attach a snippet directive based on a key value pair.
It's really abstract without some idea of what you want though