Skip to content

Instantly share code, notes, and snippets.

@dustintheweb
Created February 28, 2015 11:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustintheweb/167084031750a0b7776d to your computer and use it in GitHub Desktop.
Save dustintheweb/167084031750a0b7776d to your computer and use it in GitHub Desktop.
AngularJS: Multiple ternary statements in ng-class
<!doctype html>
<html ng-app="myApp">
<head>...</head>
<body ng-controller="myController" ng-class="(toggleClass1 ? 'class-1' : '')+' '+(toggleClass2 ? 'class-2' : '')">
<div>
stuff...
<div class="button1" ng-click="$toggleClass1 = !$toggleClass1"></div>
stuff...
<div class="button2" ng-click="$toggleClass2 = !$toggleClass2"></div>
</div>
</body>
</html>
(function() { 'use strict';
var app = angular.module('myApp');
//
app.controller('mainCtrl',['$scope', function($scope){
$scope.toggleClass1 = false;
$scope.toggleClass2 = false;
}]);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment