I have added span element dynamically in.ts file where I have added contenteditable attribute but when it gets rendered on web page this attribute is didnt get appeared in tag. I have added as
newHTML +=
 <span class='taggedUser' [contenteditable]='false'>${taggedUserName}  `.I want to use to this attribute. Reason: I want to highlight the user in text and for that I am adding span and its css.
how are you adding newHTML to your components html file? Are you using the innerHTML attribute like so:
[innerHTML]=newHTML
UPDATE:
Angular has a security mechanism to prevent XSS for example, So sometimes when you try to add something to your html as a string in runtime it strips some properties/styling from the html.
A simple example would be something like:
constructor(private _sanitizer: DomSanitizer) { }
ngOnInit() {
this.newHTML += this.sanitize(` <span class='taggedUser' [contenteditable]='false'>${taggedUserName}  `)
}
sanitize(htmlStr: string): SafeHtml {
return this._sanitizer.bypassSecurityTrustHtml(htmlStr);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.