简体   繁体   English

Ionic5 打字稿,我怎么能告诉我的 html 它的 html 代码 [innerHTML] 不起作用

[英]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"

he still shows me the html tags such as (</ br <div etc)他仍然向我展示了 html 标签,例如 (</br <div 等)

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.

相关问题 如何将大型HTML代码转换成字符串以在.innerHTML中使用 - How can I get my large HTML code into a string for use in .innerHTML 我怎么能告诉这个HTML代码中的javascript不影响所有按钮? - How can i tell the javascript in this html code not to influence all the buttons? 如何复制 HTML 中某个部分的 innerHTML 并创建它的精确副本作为其子项? - How can I copy the innerHTML of a section in HTML and create an exact copy of it as its child? 我无法让我的 JavaScript 代码在我的 HTML 文件中工作 - I can not get my JavaScript code to work in my HTML file 如何使用json的ionic 2在HTML中显示此数据? - How can i show this data in my html with ionic 2 from a json? 我无法使用HTML(innerHTML)中的Javascript显示排序后的数组 - I can't display my sorted array with Javascript in HTML (innerHTML) 使用javascript,如何判断DOM中的HTML对象是否不在HTML源代码中? - Using javascript, how can I tell if an HTML object in the DOM is not in the HTML source code? 如何在 HTML 中查看我的 typeScript 的结果? - How can i see the result form my typeScript in the HTML? 有人能告诉我,我对HTML / JS代码的解释是否正确? - Can someone tell me if I am right in my explanation of HTML/JS code? 在动态更改之前,如何告诉jquery html()元素到其原始值? - How can I tell jquery to html( ) an element to its original value, before it was dynamically changed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM