@@ -16,6 +16,7 @@ import {
1616 ViewChild ,
1717 ViewEncapsulation
1818} from '@angular/core' ;
19+ import { DomSanitizer , SafeResourceUrl } from '@angular/platform-browser' ;
1920import { fromEvent } from 'rxjs' ;
2021import { 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