码迷,mamicode.com
首页 > 其他好文 > 详细

angular 中的[ngClass]、[ngStyle]

时间:2019-05-20 17:29:00      阅读:458      评论:0      收藏:0      [点我收藏+]

标签:enter   value   center   url   html   item   welcome   ppc   demo   

<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;
}

   效果:

技术图片

angular 中的[ngClass]、[ngStyle]

标签:enter   value   center   url   html   item   welcome   ppc   demo   

原文地址:https://www.cnblogs.com/loaderman/p/10894831.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!