angular 中嵌套 iframe 報錯

錯誤以下this

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

解決url

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);
  }
} 

經過過濾器來解決 spa

使用code

<iframe width="100%" height="300" [src]="url | safe"></iframe>
相關文章
相關標籤/搜索