admin管理员组文章数量:1200357
I am using a wysiwyg editor in my Angular component, when i try to preview the content of the editor, (after i apply center to the text), i get this warning:
WARNING: sanitizing HTML stripped some content (see ).
platform-browser.es5.js:1015
when i inspect the html:
<p>Text Here...</p>
but when i try to use console.log() to preview the content of the editor i get:
<p style="text-align: center;">Text Here...</p>
I am using a wysiwyg editor in my Angular component, when i try to preview the content of the editor, (after i apply center to the text), i get this warning:
WARNING: sanitizing HTML stripped some content (see http://g.co/ng/security#xss).
platform-browser.es5.js:1015
when i inspect the html:
<p>Text Here...</p>
but when i try to use console.log() to preview the content of the editor i get:
<p style="text-align: center;">Text Here...</p>
Share
Improve this question
edited Sep 8, 2020 at 14:42
Salim Ben Hassine
asked Dec 6, 2017 at 19:12
Salim Ben HassineSalim Ben Hassine
3491 gold badge6 silver badges20 bronze badges
1 Answer
Reset to default 24This is by design in Angular 2+ for security reasons. You can workaround it by using the DomSanitizer class.
For example you can make a pipe that prevents sanitization of the value:
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
@Pipe({ name: 'noSanitize' })
export class NoSanitizePipe implements PipeTransform {
constructor(private domSanitizer: DomSanitizer) {
}
transform(html: string): SafeHtml {
return this.domSanitizer.bypassSecurityTrustHtml(html);
}
}
Then you can use it in binding for example like this:
<div [innerHTML]="htmlText | noSanitize">
</div>
本文标签: javascriptAngularsanitizing HTML stripped some content on css styleStack Overflow
版权声明:本文标题:javascript - Angular : sanitizing HTML stripped some content on css style - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738577906a2100984.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论