To conditionally set a class on the
مقالات ذات صلة
element based on the value of account.newPms
, you can use the ng-class
directive in AngularJS. Here’s how you can modify your HTML template code:html<li class="icon-element pms" ng-class="{'is-zero': account.newPms === '0'}">
<div class="icon" ng-include="iconPm">div>
<span class="counter">{{account.newPms}}span>
li>
In this code, ng-class
is used to conditionally apply the class 'is-zero'
to the
account.newPms === '0'
. If account.newPms
is equal to '0'
, the class 'is-zero'
will be applied to the
Make sure to define the 'is-zero'
class in your CSS with the styles you want to apply when account.newPms
is '0'
.
المزيد من المعلومات
إذا كانت قيمة account.newPms
تساوي '0'
، يتم تطبيق الفئة 'is-zero'
على عنصر
، وإذا كانت قيمة account.newPms
غير '0'
، فلن يتم تطبيق الفئة. يمكنك تعريف الفئة 'is-zero'
في CSS الخاص بك بالأنماط التي ترغب في تطبيقها عندما تكون account.newPms
تساوي '0'
.
عند استخدام ng-class
، يمكنك أيضًا تطبيق أكثر من فئة استنادًا إلى شروط متعددة. على سبيل المثال، إذا كنت ترغب في تطبيق الفئة 'is-even'
عندما تكون account.newPms
قيمة زوجية، يمكنك القيام بذلك كما يلي:
html<li class="icon-element pms" ng-class="{'is-zero': account.newPms === '0', 'is-even': account.newPms % 2 === 0}">
<div class="icon" ng-include="iconPm">div>
<span class="counter">{{account.newPms}}span>
li>
في هذا المثال، إذا كانت قيمة account.newPms
زوجية، سيتم تطبيق الفئة 'is-even'
على العنصر
'is-zero'
إذا كانت account.newPms
تساوي '0'
.