I'm trying to dynamically create some HTML based on query results from my database. As a result, I'm not able to have the HTML ready in the Angular template to bind attributes to. The HTML is added via [innerHTML]
using data from a string in the database. Given Angular's AOT compiling method, the string in the database cannot include an attribute to bind to.
This following is my attempt at resolving this particular request.
I would like to set the following attribute, whereby once the innerHTML has rendered, I can find the 'header' element by the ID and add an attribute that displays a top border based on a variable in the component.ts file.
However, I keep receiving the following error:
Failed to execute 'setAttribute' on 'Element': '[style.border-top-color]' is not a valid attribute name.
myChosenColour = "#007cbe"
...
document.getElementById('header').setAttribute('[style.border-top-color]', this.myChosenColour)
It's worth noting: I need the square brackets to bind to the local variable, as there will be inputs on screen where new values can be entered, and therefore the colour will be changed and will need to update dynamically.