ionic2 加载html

1.导入模块

import { DomSanitizer } from '@angular/platform-browser';

2.在构造函数添加

constructor(private sanitizer: DomSanitizer) {
   
  }

3.页面上使用方法 

3.1使用变量

ts中:

assembleHTML =this.sanitizer.bypassSecurityTrustHtml(‘<p style="color:red;">测试加载html</p>’

html中:

 <div  [innerHTML]="assembleHTML"></div>

3.2使用方法

ts中:

assembleHTML(){ 
  return this.sanitizer.bypassSecurityTrustHtml(‘<p style="color:red;">测试加载html</p>’);
}

html中:

<div  [innerHTML]="assembleHTML()"></div>

参:http://blog.csdn.net/u010730897/article/details/53609173

  http://www.cnblogs.com/cjxhd/p/6607108.html

posted @ 2017-05-18 17:10  心的记忆  阅读(595)  评论(0编辑  收藏  举报