我在 Angular 9 中有应用程序并使用 DomSanitazer 构建 img url。我得到错误:
Not allowed to load local resource: file:///C:/MyApp/Images/uploads/fbf8152f-ccea-45a2-b9a9-150cd4c421a5/mmm_3424.png
在 component.ts 我有:
import {
SafeResourceUrl,
DomSanitizer
} from '@angular/platform-browser';
public avatarSafeFileUrl: SafeResourceUrl;
当我加载 img 时:
this.avatarSafeFileUrl = this.domSanitizer.bypassSecurityTrustResourceUrl(this.myAvatar.filePath);
在html中我有:
<img [src]="avatarSafeFileUrl" />
我得到像上面这样的错误。