相关疑难解决方法(0)

如何使用ngStyle(angular2)添加背景图像?

如何使用ngStyle添加背景图像?我的代码不起作用:

this.photo = 'http://dl27.fotosklad.org.ua/20121020/6d0d7b1596285466e8bb06114a88c903.jpg';

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

html javascript css angular

90
推荐指数
6
解决办法
10万
查看次数

在RC.1中,使用绑定语法无法添加某些样式

风格如

<div [style.background-image]="\'url(\' + image + \')\'">Background</div>
<div [style.transform]="rotate(7deg)"
Run Code Online (Sandbox Code Playgroud)

不再添加

css angular

68
推荐指数
1
解决办法
5万
查看次数

如何在Angular 4中使用ngStyle作为后台URL

我有以下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:

Angular 2中背景图像URL的属性属性绑定

如何使用ngStyle(angular2)添加背景图像?

到目前为止尝试过:

<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.

image angular

8
推荐指数
2
解决办法
2万
查看次数

标签 统计

angular ×3

css ×2

html ×1

image ×1

javascript ×1