Skip to content

Commit

Permalink
Merge pull request #223 from stasusov/master
Browse files Browse the repository at this point in the history
 #218: Allow gallery-image component to use unsafe urls
  • Loading branch information
MurhafSousli authored Oct 27, 2018
2 parents d569724 + 45e9f2f commit da1ace1
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Component, Input, HostBinding, OnInit, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import { DomSanitizer, SafeHtml, SafeStyle } from '@angular/platform-browser';

@Component({
selector: 'gallery-image',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<ng-container [lazyImage]="src" (loaded)="loadedImage = $event" (error)="error.emit($event)">
<ng-container [lazyImage]="src" (loaded)="loadedImage = trustCss($event)" (error)="error.emit($event)">
<div *ngIf="loadedImage; else loading"
class="g-image-item"
[style.backgroundImage]="loadedImage"></div>
Expand All @@ -21,7 +21,7 @@ import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
})
export class GalleryImageComponent implements OnInit {

loadedImage: string;
loadedImage: SafeStyle;
loadingSvg: SafeHtml;

@Input() src: string;
Expand All @@ -43,4 +43,8 @@ export class GalleryImageComponent implements OnInit {
}
}

trustCss(imageUrl: string): SafeStyle {
return this._sanitizer.bypassSecurityTrustStyle(imageUrl);
}

}

0 comments on commit da1ace1

Please sign in to comment.