[英]Ionic5 typescript, how can i tell my html its html code [innerHTML] not work
i am a nooby in ionic5(typescript) hope u can help me The code in my Html is:我是 ionic5(typescript) 的菜鸟,希望你能帮助我我的 Html 中的代码是:
[innerHTML]="jsondataservice.storageCards[1].l_content " id="last"
I've read that it might work with my own pipe somethink like that我读过它可能会与我自己的管道一起使用
import { Pipe, PipeTransform } from '@angular/core';
import {DomSanitizer} from "@angular/platform-browser";
@Pipe({
name: 'safeHtml'
})
export class SafeHtmlPipe implements PipeTransform {
sanitizer: DomSanitizer;
transform(html) {
return this.sanitizer.bypassSecurityTrustHtml(html);
}
}
i tryed but i cant find my pipe in html with我试过了,但我无法在 html 中找到我的管道
[innerHTML]="jsondataservice.storageCards[1].l_content |safeHtml" id="last"```
pls help >-<
SOLVED解决了
import { Pipe, PipeTransform } from '@angular/core';
import {DomSanitizer} from "@angular/platform-browser";
@Pipe({
name: 'safeHtml'
})
export class SafeHtmlPipe implements PipeTransform {
sanitizer: DomSanitizer;
transform (value: string): SafeHtml {
let lTextArea = document.createElement('textarea');
lTextArea.innerHTML = value;
return lTextArea.value;
}
}
<div [innerHTML]="jsondataservice.storageCards[1].l_content |safehtml" id="last" ></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.