m
sanitizing unsafe style value
Example
<div class="header" *ngIf="image" [style.background-image]="image"></div>
Import DomSanitizer
use bypassSecurityTrustStyle
method.
export class StyleComponent implements OnInit {
@Input() image: string;
constructor(private sanitization: DomSanitizer) { }
ngOnInit() {
if (this.image) {
this.image = this.sanitization.bypassSecurityTrustStyle(`url(${this.image})`);
}
}
}