I have a component in Angular, the content of which is supplied by a backend that provides HTML code. I add it to the component as inner HTML. There is a and a tag in the HTML supplied. However, while I think the styles are being honoured, I am unable to call the function in the script tag.
The <script> tag:
function ToggleDisplayMode(node)
{
var tableHeader = document.getElementById(node);
if (null != tableHeader)
{
var row = tableHeader.nextSibling;
while (row != null)
{
if ( row.style.display != "none" ) {
row.style.display = "none";
}
else {
row.style.display = "";
}
row = row.nextSibling;
}
}
}
How I am calling this function:
<a onclick="ToggleDisplayMode(<args>)"><u>show/hide</u></a>
The click doesn't work and I get the following output in the console:
> Uncaught ReferenceError: ToggleDisplayMode is not defined
> at HTMLAnchorElement.onclick (<args>)
The function is clearly defined, so I do not understand what I am doing wrong here.
I have checked several posts on the issue, but they're JQuery based. Is this an issue with how Angular might treat inner HTML?
EDIT:
The click needs to be handled by JavaScript and not Angular (because of the pecularities of this system), so ngClick or (click) will not work.
EDIT 2:
Apparently, <script> tags in innerHtml don't get executed according to this post. Will have to find another way to do this then.
<args>here?ngClickvar tableHeader = document.getElementById(node);in the second line of the function.ToggleDisplayModedoes it return anything? If not thenToggleDisplayModeis not on the global scope