码迷,mamicode.com
首页 > 其他好文 > 详细

angular 中嵌套 iframe 报错

时间:2019-05-08 20:24:22      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:private   val   name   safe   过滤器   span   code   from   class   

错误如下

Error: unsafe value used in a resource URL context
at DomSanitizationServiceImpl.sanitize...

解决

import { Pipe, PipeTransform } from ‘@angular/core‘;
import { DomSanitizer} from ‘@angular/platform-browser‘;

@Pipe({ name: ‘safe‘ })
export class SafePipe implements PipeTransform {
  constructor(private sanitizer: DomSanitizer) {}
  transform(url) {
    return this.sanitizer.bypassSecurityTrustResourceUrl(url);
  }
} 

通过过滤器来解决 

使用

<iframe width="100%" height="300" [src]="url | safe"></iframe>

  

angular 中嵌套 iframe 报错

标签:private   val   name   safe   过滤器   span   code   from   class   

原文地址:https://www.cnblogs.com/fuzitu/p/10834180.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!