البرمجة

كيفية تعيين فئة CSS إذا كان قيمة JSON Array تساوي 0

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

  • element based on the expression account.newPms === '0'. If account.newPms is equal to '0', the class 'is-zero' will be applied to the
  • element; otherwise, it won’t be applied.

    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'.

  • زر الذهاب إلى الأعلى