我正在尝试使用DomSanitizer使我的网址安全。我已按照these steps进行了操作,如下所示:
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
@Pipe({
name: 'youtube',
})
export class YoutubePipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer){}
transform(value: string, ...args) {
value = value.replace('watch?v=', 'embed/');
console.log(value);
return this.sanitizer.bypassSecurityTrustResourceUrl(value);
}
}
记录的值没问题,但我收到了错误:
ERROR TypeError: Cannot read property 'bypassSecurityTrustResourceUrl' of undefined
这对我意味着我的对象没有全部设置。我已经检查过'构造函数'被调用了,所以我在这里缺少什么?