您的位置:首页 > 其它

ionic2/3 ngClass 和ngStyle用法

2017-07-12 09:53 369 查看
ngClass第一个参数为类名称,第二个参数为boolean值,如果为true就添加第一个参数的类

[ngClass]="{'text-success':index == 0}"


ngStyle没有判断

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


ngStyle有判断

<div [ngStyle]="{'background-color':username === 'zxc' ? 'green' : 'red' }"></<div>


例如:

<ion-col col-4 *ngFor="let item of rmpp ;let i = index" (click)="choose(item.id)"> <button id="{{item.id}}" ion-button small outline [ngClass]="{'active':i === 0}">{{item.name}}</button></ion-col>


<ion-col col-4 *ngFor="let item of rmpp ;let i = index" (click)="choose(item.id)"> <button id="{{item.id}}" ion-button small outline [n
4000
gStyle]="{'color':i=== 0 ? 'green' : 'red' }">{{item.name}}</button></ion-col>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: