相关疑难解决方法(0)

在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 2中背景图像URL的属性属性绑定

我一直在努力找出background-image在许多Angular 2组件中动态更改属性的最佳方法.

在下面的示例中,我尝试使用指令background-image将div设置为@Input[ngStyle]:

import {Component, Input} from '@angular/core';
import { User } from '../models';

// exporting type aliases to enforce better type safety (https://github.com/ngrx/example-app)
export type UserInput = User;

@Component({
  selector: 'profile-sidenav',
  styles: [ `
    .profile-image {
      background-repeat: no-repeat;
      background-position: 50%;
      border-radius: 50%;
      width: 100px;
      height: 100px;
    }
  `],
  template: `  
    <div class="profile-image" [ngStyle]="{ 'background-image': url({{image}})">
    <h3>{{ username }}</h3>
  `
})

export class ProfileSidenav {
  @Input() user: UserInput;
  blankImage: string …
Run Code Online (Sandbox Code Playgroud)

css typescript angular-directive angular

27
推荐指数
2
解决办法
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

angular-directive ×1

image ×1

typescript ×1