AngularJS - Can I use data binding value depending on ternary operator

前端 未结 2 1576
梦如初夏
梦如初夏 2021-01-04 03:09

I have an ng-repeat li elements and I want to set a specific value for that li depending on whether a function returns true or false and I

相关标签:
2条回答
  • 2021-01-04 03:33

    With the release of angular 1.2, you can now use the more intuitive ternary operator inside ng-bind

    <a ng-bind="object1.hidden ? 'Maximize' : 'Minimize'"></a>
    

    or inside brackets

    <a>{{ object1.hidden ? 'Maximize' : 'Minimize' }}</a>
    
    0 讨论(0)
  • 2021-01-04 03:43

    You can do this

    {{ object1.hidden && 'Minimize' || 'Maximize' }}
    

    In angular 1.2 a real ternary operator will be added.

    0 讨论(0)
提交回复
热议问题