在angular html中使用动态网址会产生错误。

时间:2018-02-15 12:04:47

标签: angular

在我的HTML中,我使用的是:

<object #homes style="height:500px;width:1000px" data="{{homesPath}}"></object>

在TS:

constructor(
private homesProfileService: HomesProfileService,
private sanitizer: DomSanitizer) {}

this.homesPath = this.sanitizer.bypassSecurityTrustResourceUrl(
  environment.homesPath
);

但是它给出了错误:

  

错误:资源URL上下文中使用的不安全值(请参阅   http://g.co/ng/security#xss

我有什么不对的。

1 个答案:

答案 0 :(得分:1)

现在通过更改HTML中的一点来实现它的工作:

<object #homes style="height:500px;width:1000px" data="{{homesPath}}"></object>

TO:

<object #homes style="height:500px;width:1000px" [data]="homesPath"></object>

但仍然没有得到前一个不起作用的原因。 任何人都可以评论它。