angular动态设置css,在角度JS中动态应用CSS样式属性

ngStyle directive allows you to set CSS style on an HTML element dynamically.

Expression which evals to an object whose keys are CSS style names and values are corresponding values for those CSS keys. Since some CSS style names are not valid keys for an object, they must be quoted.

ng-style="{color: myColor}"

Your code will be:

If you want to use scope variables:

Here an example on fiddle that use ngStyle, and below the code with the running snippet:

angular.module('myApp', [])

.controller('MyCtrl', function($scope) {

$scope.items = [{

name: 'Misko',

title: 'Angular creator'

}, {

name: 'Igor',

title: 'Meetup master'

}, {

name: 'Vojta',

title: 'All-around superhero'

}

];

});

.pending-delete {

background-color: pink

}

name: {{item.name}}, {{item.title}}

(will be deleted)

I will hide if the color is set to 'red'.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值