Issue
Is it possible to add the " *ngIf " directive to an element created with TypeScript?
The only solution that I found yet is, depending on the condition, this element dynamically created changes it's display between 'none' or 'block'.
Tried with 'element.setAttribute()' but doesn't work. Tried with creating an element and setting it's 'innerHTML' like this:
element.innerHTML = `
<child *ngIf="condition"> ... </child>
`
Used the tag 'child' as a representation of a random element. Also didn't work.
Thanks in advance!
Solution
Your HTML string inside the innterHTML would not be parsed as the angular compiler only compiles templates at runtime when declared in the template property or external template file.
You can try running your condition in your TS file.
if(condition)
element.innerHTML = `<child> ... </child>'
Answered By - NTP
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.