Skip to content

Instantly share code, notes, and snippets.

@davidgjordan
Last active August 28, 2017 14:51
Show Gist options
  • Save davidgjordan/65560eb0775c600bc72c7eeef062b72a to your computer and use it in GitHub Desktop.
Save davidgjordan/65560eb0775c600bc72c7eeef062b72a to your computer and use it in GitHub Desktop.
Styles Background poner backgruond mediante styles
import { Component} from '@angular/core';
import { DomSanitizer} from '@angular/platform-browser'
@Component({
selector: 'app-books',
templateUrl: './books.component.html'
})
export class BooksComponent implements OnInit {
public urlImage:string;
constructor(private _sanitizer:DomSanitizer) {
this.urlImage = "assets/img/project-2.jpg" ;
}
public sanitizeImage(image: string) {
return this._sanitizer.bypassSecurityTrustStyle(`url(${image})`);
}
}
//HTML
[style.background-image]="sanitizeImage(urlImage)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment