Within my innerHtml, I have a string that looks like this:
<div class="wrapper" [innerHTML]="data.testString">
The data inside data.testString is as follows,
data.testString="<p>some info, email <a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9beffee8efdbeffee8efb5f8f4f6">[email protected]</a>"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7b0f1e080f3b0f1e080f55181416">[email protected]</a></a> info </p>";
I need to include an aria-label for the anchor tag.
<a aria-label="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2a5e4f595e6a5e4f595e04494547">[email protected]</a>" href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c8bcadbbbc88bcadbbbce6aba7a5">[email protected]</a>"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ff8b9a8c8bbf8b9a8c8bd19c9092">[email protected]</a></a>
This is the code snippet added in the .ts file
ngAfterViewInit(): void {
var myData = this.data.testString;
var element = myData!.match!(/href="([^"]*)/)![1];
var ariaLabel = "EmailId " + element;
this.data.testString=
this.data.testString!.replace('<a', '<a aria-label = "' + ariaLabel + '" ');
}
}
However, I encountered the following error
global-error-handler.ts:26 TypeError: Cannot assign to read only property 'testString' of object '[object Object]'
What steps should be taken to resolve this issue?