AngularJS: Birinchi elementda CSS-ni ng-takrorlash bilan qo'llang

Men har doim ham $ index === 0 emas, balki $ first dan foydalangan holda hal qila oladigan my ng-if shartlari orqali birinchi indeksni izlayapman.

Mening kod namunamiz:

<div class="ticket-event" ng-if="!item.hidden" ng-repeat="item in ctrl.event.items">   
   <div class="title item" ng-class="{'active': $index === $first}"></div>
</div>

element ning birinchi marta paydo bo'lishida sinf qo'shishni xohlayman.

2

6 javoblar

$ index - $ first -ni tekshirish shart emas:

<div class="title item" ng-class="{'active': $index === $first}">

Change it to:

<div class="title item" ng-class="{'active': $first}">
4
qo'shib qo'ydi
Lekin 2-satrdan o'tgan elementlar indeksi 0dan boshlanmaganida, 5, $ birinchi ko'rsatma ishlamaydi
qo'shib qo'ydi muallif Emmanuel Gabion, manba

Nima uchun CSS orqali buni amalga oshirmaysiz?

"Chiptani" ko'rsatgan holda "imlo xatolari" va "chipta-tadbir" bo'lishi kerak deb hisoblasa, CSS oddiy:

.ticket-event div:first-child {//css here }
2
qo'shib qo'ydi

Mana nima qilish kerak:

<div class="title item" ng-class='{active:$first}'></div>
2
qo'shib qo'ydi

Bu men uchun ishladi

<div class="title item" ng-class='{active:$first}'></div>
1
qo'shib qo'ydi

You can make use of $first

It will evaluate to true for the first element in ng-repeat

Shunday qilib, sizning kodingiz bo'lishi kerak

<div class="ticket-event" ng-if="!item.hidden" ng-repeat="item in ctrl.event.items">   
   <div class="title item {{$first?'active':'someotherclass'}}"></div>
</div>
0
qo'shib qo'ydi
<tr ng-class="{evaluationRow : $index==0 && item.HighlightBorder==true }" ng-repeat="item in items" >     
                <td>{{item.LearnerId}} </td>
                <td>{{item.Name}}</td>

This has worked for me. Here I'm setting CSS class for first element in ng-repeat only if a condition holds true otherwise 'No' CSS class is applied.

In above example, "evaluationRow" is the name of CSS class to apply, followed by a condition.

0
qo'shib qo'ydi
Angular Uzbekistan
Angular Uzbekistan
107 ishtirokchilar

Guruh Angular bo'yicha muloqot qilish uchun ochilgan Sizni qiziqtirsa: @nodejs_uz @react_uz @angular_uz @yiiframework_uz @js_uzb @typescript_uzb @vuejs_uz @ngTashkent @laravel_uz @uzdevgroup Ish o'rinlari @UzDev_jobs

ngTashkent
ngTashkent
77 ishtirokchilar

Правила просты: 1. Не хамить 2. Не хейтить 3. Реакт не нужен Ссылки: https://t.me/angular_ru - старший брат https://t.me/angular_uz - ангулар на узбекском @js_uzb @vuejs_uz @react_uz @nodejs_uz @yiiframework_uz @uzdevgroup @UzDev_Jobs @tasdev_talks