错误如下

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>

  

相关文章:

  • 2021-11-13
  • 2021-10-17
  • 2021-08-07
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
  • 2021-07-31
  • 2022-12-23
猜你喜欢
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
相关资源
相似解决方案