如何允许HTML返回angular2管道? [英] How to allow html in return of angular2 pipe?
本文介绍了如何允许HTML返回angular2管道?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个返回html字符串的管道,但是该字符串输出可能是安全性的默认值而转义.我确定必须有一个允许使用html的选项,但是当我搜索文档时找不到它.
I have a pipe that returns a html string, however the string outputs escaped presumably as a default for security. I'm sure there must be an option to allow html instead but cant find it when I search docs.
如何告诉管道允许实际的html呈现?
How can I tell the pipe to allow actual html to render?
推荐答案
使用绑定到 innerHTML
或 <span [innerHTML]="someString | toHtmlPipe"></span>
.参见此小品:
Use bindings to innerHTML
or outerHTML
to render already escaped html. For example <span [innerHTML]="someString | toHtmlPipe"></span>
. See this plunk:
@Pipe({
name: 'wrapBold'
})
class WrapBold {
transform(content) {
return `<b>${content}</b>`;
}
}
@Component({
selector: 'my-app',
pipes: [WrapBold],
template: `
<div>
Hello <span [outerHTML]="content | wrapBold"></span>
</div>
`
})
export class App {
constructor() {
this.content = 'Angular2'
}
}
这篇关于如何允许HTML返回angular2管道?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文