我正在尝试使用DomSanitizer来清理组件中的动态URL,我似乎无法弄清楚为此服务指定Provider的正确方法是什么.
我正在使用Angular 2.0.0-rc.6
这是我目前的组成部分:
@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() {}
}
Run Code Online (Sandbox Code Playgroud)
这会导致this.sanitizer.bypassSecurityTrustResourceUrl is not a function运行时出错.
有人能告诉我一个如何正确提供DomSanitizer提供商的例子吗?谢谢!
javascript typescript angular-services angular angular-dom-sanitizer