Shaper Shaper - 4 years ago 105
AngularJS Question

AngularJS - Conditionally apply style using ng-style to first element in ng-repeat

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

I will appreciate your help!

Here is the code:

<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"});
};
}]);


Thanks!

Answer Source
<div class="row" 
    ng-style="{ true : rowCss }[$first]" 
    ng-repeat="top in gridObj">
    ...

Plunker

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download