![](/img/trans.png)
[英]Angular-CLI Error: Return type of public method from exported class has or is using name 'ErrorObservable' from external module but cannot be named
[英]Class has or is using name 'SafeUrl' from external module but cannot be named
我正在使用sanitizer.bypassSecurityTrustUrl
在页面上放置指向blobURL的链接。 只要我不编译项目,此方法就可以正常工作。
import {DomSanitizer} from '@angular/platform-browser';
export class AppComponent {
constructor(private sanitizer: DomSanitizer) {
}
sanitize(url: string) {
return this.sanitizer.bypassSecurityTrustUrl(url);
}
}
清理功能采用如下网址:
blob:http://localhost:4200/7c1d7221-aa0e-4d98-803d-b9be6400865b
如果我使用AoT编译,则会收到以下错误消息:
模块构建失败:错误:/.../src/app/app.component.ts(18,3):导出类的公共方法的返回类型具有或正在使用外部模块“ / ...”中的名称“ SafeUrl” / node_modules / @ angular / platform-browser / src / security / dom_sanitization_service”,但无法命名。)
我在Angular 2.1.0中使用CLI
有人知道我该如何解决这个问题? 还是应该将其报告为错误?
因此,似乎我不得不向该方法添加SafeUrl
的返回类型
sanitize(url: string):SafeUrl {
return this.sanitizer.bypassSecurityTrustUrl(url);
}
非常感谢alxhub
就我而言,我正在初始化这样的属性:
public img64 = this.domSanitizer.bypassSecurityTrustResourceUrl('data:image/jpg;base64,' + this.base64Image);
导致相同的错误。
感谢@mottosson,我弄对了(只需添加类型SafeUrl):
public img64: SafeUrl = this.domSanitizer.bypassSecurityTrustResourceUrl('data:image/jpg;base64,' + this.base64Image);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.