AngularJS-有条件地将使用ng-style的样式应用于ng-repeat中的第一个元素 [英] AngularJS - Conditionally apply style using ng-style to first element in ng-repeat
本文介绍了AngularJS-有条件地将使用ng-style的样式应用于ng-repeat中的第一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个样式对象,我只需要为第一个元素设置另一个CSS样式. 我为此专门创建了一条指令,但是它不起作用
I have an object of styles and I need to set another css style only for the first element. I created a directive especially for that, but it doesn't work
感谢您的帮助!
这是代码:
<div class="row" ng-style="rowCss" ng-repeat="top in gridObj" ng-zero>
$scope.rowCss = {
"height" : rowAndSquareHeight,
"padding-top": baseLine
}
editorApp.directive('ngZero', ['$document', '$parse', function($document, $parse) {
return function(scope, element, attr) {
$(element).css({"padding-top" : "0px"});
};
}]);
谢谢!
推荐答案
<div class="row"
ng-style="{ true : rowCss }[$first]"
ng-repeat="top in gridObj">
...
Plunker
这篇关于AngularJS-有条件地将使用ng-style的样式应用于ng-repeat中的第一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文