angularjs - Change button colors dynamically using angular js -


i have 2 buttons in green , red color. want change color of button. suppose if click on red colored button green colored button change gray. when click on green colored button , red colored button change gray. how can achieve in angular js?

please check working example: http://plnkr.co/edit/dhqr4amhbkqsgg4gwrb4?p=preview

controller

var app = angular.module('plunker', []); app.controller('mainctrl', function($scope) {   $scope.click = ''; }); 

html

<button ng-click="click = 'red'" ng-class="{'red': click == 'red' || click == '', 'grey': click == 'green'}"> red</button> <button  ng-click="click = 'green'" ng-class="{'green': click == 'green' || click == '', 'grey': click == 'red'}">green</button> 

css

.grey {   background-color :#808080; }  .red {   background-color :#ff0000; } .green {   background-color :#008000; } 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -

Why does a .NET 4.0 program produce a system.unauthorizedAccess error on a Windows Server 2012 machine with .NET 4.5 installed? -