DomSanitizer を使用してコンポーネント内の動的 URL をサニタイズしようとしていますが、このサービスのプロバイダーを指定する正しい方法がわかりません。
これが私の現在のコンポーネントです:
@Component({
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ],
providers: [ DomSanitizer ],
})
export class AppComponent implements OnInit
{
public url: SafeResourceUrl;
constructor(private sanitizer: DomSanitizer) {}
ngOnInit() {
let id = 'an-id-goes-here';
let url = `https://www.youtube.com/embed/${id}`;
this.videoUrl = this.sanitizer.bypassSecurityTrustResourceUrl(url);
}
ngOnDestroy() {}
}
this.sanitizer.bypassSecurityTrustResourceUrl is not a function
これにより、実行時にエラーが発生します。
DomSanitizer のプロバイダーを適切に提供する方法の例を教えてもらえますか? ありがとう!