ng-class – Stepan Suvorov Blog https://stepansuvorov.com/blog Release 2.0 Wed, 26 Aug 2015 15:40:52 +0000 en-US hourly 1 https://wordpress.org/?v=6.3.1 AngularJs: intersting syntax for complex ng-class conditions https://stepansuvorov.com/blog/2015/08/angularjs-intersting-syntax-for-complex-ng-class-conditions/ https://stepansuvorov.com/blog/2015/08/angularjs-intersting-syntax-for-complex-ng-class-conditions/#respond Wed, 26 Aug 2015 15:39:37 +0000 http://stepansuvorov.com/blog/?p=2824 Continue reading ]]> Just now I got known quite interesting condition syntax for ng-class (from stackoverflow answer):

[javascript gutter=”0″]
ng-class="{admin:’enabled’, moderator:’disabled’, ”:’hidden’}[user.role]"
[/javascript]

it seems that there is not good explanation for such case in documentation.
being inspired by this possibility I decided to create even more complex condition:
[javascript gutter=”0″]
ng-class="connections.length && ({true:’open’, false:’close’}[!!manager.showConnections])"
[/javascript]

(flag open/close will be shown only if there are some connections for current manager)

]]>
https://stepansuvorov.com/blog/2015/08/angularjs-intersting-syntax-for-complex-ng-class-conditions/feed/ 0