I have ng-repeat and only want to apply style to the first div with class type in ng-repeat.
div
type
<div class="my-list" ng-repeat="item in list"> <div class="type"> <span>{{item.label}}</span> </div> <div class="check"> <span>{{item.ischecked}}</span> </div> </div>
I tried the following but applied CSS to all divs with class type
divs
.my-list .type:first-child
You can use $first , which indicates the first iteration in ng-repeat .
$first
ng-repeat
<div class="my-list" ng-repeat="item in list"> <div class="type" ng-class="{myClass:$first}"> <span>{{item.label}}</span> </div> <div class="check"> <span>{{item.ischecked}}</span> </div> </div>
Basically you need to do the opposite.
.my-list:first-child .type{ color:red; }
ng-repeat will put multiple .my-list , and you want to target .type only of the first div. So apply a selector to .my-list .
.my-list
.type
Source: https://habr.com/ru/post/974708/More articles:Dotted line drawing with CGContextSetLineDash - iosFirebase hosting SEO for SPA - seoRoslyn Data Flow Analysis - Ambiguous Values ββfor WrittenInside and Locations - c #Presentation of the interface for the application Ember.js HTM5 => Phone Gap (or alternative stack) - androidError: tomEE is required to support EAR / EJB deployment error message - spring-mvcNode Sequelize, which does not allow auto-generated UUIDs on the primary key * if * the field name is not equal to 'id' - node.jsConvert hex to string in C? - cWhat is the difference between a component and a service dependency? - c #How to pass ViewData value to Editor Template by @ Html.EditorFor - .netCannot get UserDetailsManager using Spring Boot Configuration and Java - javaAll Articles