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.
How can I tell the pipe to allow actual html to render?
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'
}
}