Skip to content

Commit 616f59f

Browse files
authored
fix(module:image): preview the local upload image error (#7615)
1 parent f6a8044 commit 616f59f

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

components/image/image-preview.component.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
ViewChild,
1717
ViewEncapsulation
1818
} from '@angular/core';
19+
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
1920
import { fromEvent } from 'rxjs';
2021
import { takeUntil } from 'rxjs/operators';
2122

@@ -75,7 +76,7 @@ const initialPosition = {
7576
class="ant-image-preview-img"
7677
#imgRef
7778
*ngIf="index === imageIndex"
78-
[attr.src]="image.src"
79+
[attr.src]="sanitizerResourceUrl(image.src)"
7980
[attr.srcset]="image.srcset"
8081
[attr.alt]="image.alt"
8182
[style.width]="image.width"
@@ -197,7 +198,8 @@ export class NzImagePreviewComponent implements OnInit {
197198
public nzConfigService: NzConfigService,
198199
public config: NzImagePreviewOptions,
199200
private overlayRef: OverlayRef,
200-
private destroy$: NzDestroyService
201+
private destroy$: NzDestroyService,
202+
private sanitizer: DomSanitizer
201203
) {
202204
this.zoom = this.config.nzZoom ?? 1;
203205
this.rotate = this.config.nzRotate ?? 0;
@@ -347,6 +349,10 @@ export class NzImagePreviewComponent implements OnInit {
347349
}
348350
}
349351

352+
sanitizerResourceUrl(url: string): SafeResourceUrl {
353+
return this.sanitizer.bypassSecurityTrustResourceUrl(url);
354+
}
355+
350356
private updatePreviewImageTransform(): void {
351357
this.previewImageTransform = `scale3d(${this.zoom}, ${this.zoom}, 1) rotate(${this.rotate}deg)`;
352358
}

0 commit comments

Comments
 (0)