查看: 23|回覆: 0

angular 中的[ngClass]、[ngStyle]

[複製鏈接]

5

主題

0

回帖

0

積分

热心网友

金币
0
閲讀權限
220
精華
0
威望
0
贡献
0
在線時間
0 小時
註冊時間
2009-1-20
發表於 2019-5-20 16:25:00 | 顯示全部樓層 |閲讀模式
<div style="text-align:center">
  <h1>
    Welcome to {{ title }}!
  </h1>
</div>


<div [ngClass]="{'red': true, 'blue': false}"> 这是一个 div</div>

<div [ngClass]="{'red': flag, 'blue': !flag}">这是一个 div </div>

<ul>
<li *ngFor="let item of arr, let i = index"> <span [ngClass]="{'red': i==0}">{{item}}</span>
</li> 
</ul>


<div [ngStyle]="{'background-color':'green'}">你好 ngStyle</div>

<div [ngStyle]="{'background-color':attr}">你好 ngStyle</div>
.red{
    color: red
}
.blue{color: blue}
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title = 'angulardemo';
  inputValue='0'
  attr='red'
  arr= [1, 3, 4, 5, 6]
  public flag=false;
}

   效果:

回覆

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即注册

本版積分規則

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部