angular 2从cms服务生成部分html

angular 2从cms服务生成部分html,angular,content-management-system,Angular,Content Management System,所以我有CMS页面的一部分,我使用简单的http服务获取数据并显示在页面上。但问题是,在开发阶段,我想嘲弄这些服务 public getComponentHtml(componentKey: string): Observable<string> { if (this.envName === 'dev') { return Observable.of('<h1>{{isLogged()}}</h1>') } return this.http.ge

所以我有CMS页面的一部分,我使用简单的http服务获取数据并显示在页面上。但问题是,在开发阶段,我想嘲弄这些服务

public getComponentHtml(componentKey: string): Observable<string> {
 if (this.envName === 'dev') {
    return Observable.of('<h1>{{isLogged()}}</h1>')
 }
 return this.http.get('cms?key=' + componentKey)
  .map((response: Response) => response.json())
  .map((data: any) => {
    return data.componentHtml;
  });
}
我甚至尝试使用:

domSanitizer.bypassSecurityTrustHtml('html in string')//but nothing changed

因此,在模拟htlms的情况下,甚至不计算表达式。有什么想法吗?

您可以添加类似管道的

@Pipe({
  name: 'sanitizeHtml'
})
export class SanitizeHtmlPipe implements PipeTransform {

  constructor(private _sanitizer:DomSanitizer) {
  }

  transform(v:string):SafeHtml {
    return this._sanitizer.bypassSecurityTrustHtml(v);
  }
}
将管道添加到内部html数据。像

<div [innerHtml]="menu | sanitizeHtml"></div>

另请参见上面链接中的html outlet,非常有魅力,谢谢。
@Pipe({
  name: 'sanitizeHtml'
})
export class SanitizeHtmlPipe implements PipeTransform {

  constructor(private _sanitizer:DomSanitizer) {
  }

  transform(v:string):SafeHtml {
    return this._sanitizer.bypassSecurityTrustHtml(v);
  }
}
<div [innerHtml]="menu | sanitizeHtml"></div>