我有一个角度为 8 的应用程序。
我有这样的服务:
@Injectable({
providedIn: 'root'
})
export class GetProfileImageUrl {
profileImagefile: File;
constructor(private sanitizer: DomSanitizer) {}
profileImageUrlDefault() {
return this.profileImagefile === null
? '/assets/placeholder.jpg'
: this.sanitizer.bypassSecurityTrustUrl(window.URL.createObjectURL(this.profileImagefile));
}
}
我有一个组件,我在其中调用这个函数,如下所示:
get profileImageUrl() {
return this.getImageUrl.profileImageUrlDefault;
}
在构造函数中我有这个:
private getImageUrl: GetProfileImageUrl
模板如下所示:
<img [src]="profileImageUrl" width="147px" />
但我收到此错误:
profileImageUrlDefault()%20%7B%20%20%20%20%20%20%20%20return%20this.profileImagefile%20===%20null%20%20%20%20%20%20%20%20%20%20%20%20:1 GET http://localhost:4200/profileImageUrlDefault()%20%7B%20%20%20%20%20%20%20%20return%20this.profileImagefile%20===%20null%20%20%20%20%20%20%20%20%20%20%20%20?%20%27/assets/placeholder.jpg%27%20%20%20%20%20%20%20%20%20%20%20%20:%20this.sanitizer.bypassSecurityTrustUrl(window.URL.createObjectURL(this.profileImagefile));%20%20%20%20} 404 (Not Found)
Image (async)
所以我的问题是。我必须改变什么?
谢谢
抱歉,这是我的类型:
如果我这样做:
get profileImageUrl() {
return this.getImageUrl.profileImageUrlDefault();
}
我收到此错误:
core.js:5871 ERROR TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.
at GetProfileImageUrl.profileImageUrlDefault (get-profile-image-url.ts:15)
at ProfileInformationComponent.get profileImageUrl [as profileImageUrl] (profile-information.component.ts:86)
at ProfileInformationComponent_Template (profile-information.component.html:3)
at executeTemplate (core.js:11926)
at refreshView (core.js:11773)
at refreshComponent (core.js:13213)
at refreshChildComponents (core.js:11504)
at refreshView (core.js:11825)
at refreshComponent (core.js:13213)
at refreshChildComponents (core.js:11504)
隔江千里
相关分类