在Ionic2页面中打印html内容

Print html content in Ionic2 page

本文关键字:打印 html 内容 Ionic2      更新时间:2023-09-26

我有一个ionc2页面,我想在ion项内打印HTML:这是离子2页面:

@Page({
    templateUrl: './html-page.html',
})
export class Demo{
    htmlString:string = "Hello<br/><br/>Html"
    constructor() {
    }
}

这是相应的模板:

<ion-content>
    <ion-card>
        {{htmlString}}
    </ion-card>
</ion-content>

现在输出Hello<br/><br/>Html但我想要

你好

Html

将被输出。

请用这种方法试试。

<ion-content>
<ion-card>
<div [innerHTML] = "'<p>' + htmlString + '</p>'"></div>
</ion-card>
</ion-content>

希望这对你有帮助。谢谢

如果你想显示渲染你的html文本,也可以使用iframe。

some.html

Hello<br/><br/>Html

然后:-

<ion-content>
    <ion-card>
        <iframe src="some.html"></iframe>
    </ion-card>
</ion-content>