Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

984
Views
¿Cómo agregar una imagen de fondo usando ngStyle (angular2)?

¿Cómo usar ngStyle para agregar una imagen de fondo? Mi código no funciona:

 this.photo = 'http://dl27.fotosklad.org.ua/20121020/6d0d7b1596285466e8bb06114a88c903.jpg'; <div [ngStyle]="{'background-image': url(' + photo + ')}"></div>
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Creo que podrías intentar esto:

 <div [ngStyle]="{'background-image': 'url(' + photo + ')'}"></div>

Al leer tu expresión ngStyle , supongo que te perdiste algunos "'"...

over 4 years ago · Santiago Trujillo Report

0

También puedes probar esto:

[style.background-image]="'url(' + photo + ')'"

over 4 years ago · Santiago Trujillo Report

0

import {BrowserModule, DomSanitizer} from '@angular/platform-browser' constructor(private sanitizer:DomSanitizer) { this.name = 'Angular!' this.backgroundImg = sanitizer.bypassSecurityTrustStyle('url(http://www.freephotos.se/images/photos_medium/white-flower-4.jpg)'); }
 <div [style.background-image]="backgroundImg"></div>

Ver también

  • https://angular.io/docs/ts/latest/api/platform-browser/index/DomSanitizer-class.html
  • En RC.1, algunos estilos no se pueden agregar usando la sintaxis de enlace
  • Ejemplo de Plunker
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!