将带有html标记的文本显示为html
我正在尝试将文本文件显示为html。我用的是离子型的。 我正在发送一个html格式的响应,但以文本文件的形式发送到配置文件页面。它位于.ts页的变量名中将带有html标记的文本显示为html,html,angular,ionic-framework,Html,Angular,Ionic Framework,我正在尝试将文本文件显示为html。我用的是离子型的。 我正在发送一个html格式的响应,但以文本文件的形式发送到配置文件页面。它位于.ts页的变量名中 @Component({ selector: 'page-profile', templateUrl: 'profile.html', }) export class ProfilePage{ name: any; constructor(public navCtrl: NavController, public navPar
@Component({
selector: 'page-profile',
templateUrl: 'profile.html',
})
export class ProfilePage{
name: any;
constructor(public navCtrl: NavController, public navParams: NavParams) {
this.name = navParams.get('name');
现在,我正试图使用html格式显示它
<div [innerHtml]="name">{{name}}</div>
{{name}
但我得到的是文本格式,而不是html。如何以html格式显示?您需要使用绕过您提供的html(绕过SecurityTrustHTML)
在此处阅读更多信息:发布
名称
值
constructor(public navCtrl: NavController,
public navParams: NavParams,
private sanitizer: DomSanitizer) {
this.name = sanitizer.bypassSecurityTrustHtml(navParams.get('name'));
}