1

スタイルのオブジェクトがあり、最初の要素だけに別の CSS スタイルを設定する必要があります。そのために特別にディレクティブを作成しましたが、機能しません

私はあなたの助けに感謝します!

コードは次のとおりです。

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

ありがとう!

4

4 に答える 4

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

プランカー

于 2014-08-07T07:29:34.747 に答える
4

そのためのディレクティブは必要ありません。ng-repeat スコープは、$first最初の要素に当てはまる繰り返しスコープのプロパティを公開します。最初の行のクラスを定義し、それを適用するために ng-class を使用できます

ng-class="{'my-first-class':$first}"

于 2014-08-07T07:25:38.760 に答える