Table Of Contents

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})`);
    }
  }

}

留言