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
Post a Comment