How to use ngStyle for background url in Angular 4

后端 未结 7 644
逝去的感伤
逝去的感伤 2020-12-28 21:56

I have below html:

  
  • 相关标签:
  • 7条回答
    • 2020-12-28 22:34

      background-url is incorrect CSS, use background or background-image instead.

      Here is an example of correct syntax:

      <div [ngStyle]="{'background': '#fff url(' + article.uri + ') no-repeat 0 0'}"></div>
      

      Your full example would look like this:

      <li *ngFor="let article of arr; let i=index;" >
         <div *ngIf="i == 0" 
               class="w3l_banner_nav_right_banner" 
               [ngStyle]="{'background': '#fff url(' + article.uri + ') no-repeat 0 0'}" >
           <h3> Make your <span>food</span> with Spicy. </h3>
                  <div class="more">
                      <a href="products.html" class="button--saqui button--round-l button--text-thick" data-text="Shop now">Shop now1</a>
                  </div>
          </div>
      </li>
      
      0 讨论(0)
    提交回复
    热议问题