如何使用ngStyle添加背景图像?我的代码不起作用:
this.photo = 'http://dl27.fotosklad.org.ua/20121020/6d0d7b1596285466e8bb06114a88c903.jpg';
<div [ngStyle]="{'background-image': url(' + photo + ')}"></div>
Run Code Online (Sandbox Code Playgroud) 风格如
<div [style.background-image]="\'url(\' + image + \')\'">Background</div>
<div [style.transform]="rotate(7deg)"
Run Code Online (Sandbox Code Playgroud)
不再添加
我有以下html:
<li>
<div class="w3l_banner_nav_right_banner1" style="background:url('./assets/images/2.jpg') no-repeat 0px 0px;">
<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 now</a>
</div>
</div>
</li>
Run Code Online (Sandbox Code Playgroud)
问题:
我想/assets/images/2.jpg用动态变量替换图像url {{ article.uri }}.
我尝试了几种方式从下面ref:
到目前为止尝试过:
<li *ngFor="let article of arr;let i=index;">
<div *ngIf="i == 0" class="w3l_banner_nav_right_banner" [ngStyle]="{ 'background-url': 'url('+article.uri+')'} no-repeat 0px 0px;">
<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>
Run Code Online (Sandbox Code Playgroud)
我正在使用Angular 4.1.3.