[英]Class has or is using name 'SafeUrl' from external module but cannot be named
I'm using sanitizer.bypassSecurityTrustUrl
to put links to blobURL's on the page. 我正在使用
sanitizer.bypassSecurityTrustUrl
在页面上放置指向blobURL的链接。 This works just fine as long as I don't AoT compile the project. 只要我不编译项目,此方法就可以正常工作。
import {DomSanitizer} from '@angular/platform-browser';
export class AppComponent {
constructor(private sanitizer: DomSanitizer) {
}
sanitize(url: string) {
return this.sanitizer.bypassSecurityTrustUrl(url);
}
}
The sanitize function takes a URL like this: 清理功能采用如下网址:
blob:http://localhost:4200/7c1d7221-aa0e-4d98-803d-b9be6400865b
If I use AoT compilation I get this error message: 如果我使用AoT编译,则会收到以下错误消息:
Module build failed: Error: /.../src/app/app.component.ts (18,3): Return type of public method from exported class has or is using name 'SafeUrl' from external module "/.../node_modules/@angular/platform-browser/src/security/dom_sanitization_service" but cannot be named.)
模块构建失败:错误:/.../src/app/app.component.ts(18,3):导出类的公共方法的返回类型具有或正在使用外部模块“ / ...”中的名称“ SafeUrl” / node_modules / @ angular / platform-browser / src / security / dom_sanitization_service”,但无法命名。)
I'm using CLI with Angular 2.1.0 我在Angular 2.1.0中使用CLI
Anybody knows how I can circumvent this problem? 有人知道我该如何解决这个问题? Or should it be reported as a bug?
还是应该将其报告为错误?
In my case i was initiating an attribute like this : 就我而言,我正在初始化这样的属性:
public img64 = this.domSanitizer.bypassSecurityTrustResourceUrl('data:image/jpg;base64,' + this.base64Image);
Resulting in the same error. 导致相同的错误。
Thanks to @mottosson I got it right (just add the type SafeUrl): 感谢@mottosson,我弄对了(只需添加类型SafeUrl):
public img64: SafeUrl = this.domSanitizer.bypassSecurityTrustResourceUrl('data:image/jpg;base64,' + this.base64Image);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.