I have 3 different buttons, which are A, B and C. Right now, my button is OK and showed active when first time clicked. But when I click for second time at the same button, it didn't showed inactive button. Before this, I'm also refer to this, but nothing can help me. Here is the demo and below is my code:
HTML:
<button class="button button-primary" ng-model="button.a" ng-click="select(button.a)" ng-class="button.a.clicked?'button-dark':'button-stable'">
A
</button>
<button class="button button-primary" ng-model="button.b" ng-click="select(button.b)" ng-class="button.b.clicked?'button-dark':'button-stable'">
B
</button>
<button class="button button-primary" ng-model="button.c" ng-click="select(button.c)" ng-class="button.c.clicked?'button-dark':'button-stable'">
B
</button>
Javascript:
$scope.button = {};
$scope.button.a = {clicked: false}
$scope.button.b = {clicked: false}
$scope.button.c = {clicked: false}
$scope.select = function(button){
$scope.button.a.clicked = false;
$scope.button.b.clicked = false;
$scope.button.c.clicked = false;
button.clicked = true;
};
Really need your help, thank you.
see my the snippet below. you forgot to toggle the state for selected buttons.
angular.module('mySuperApp', ['ionic'])
.controller('MyCtrl',function($scope) {
$scope.button = {};
$scope.button.a = {clicked: false}
$scope.button.b = {clicked: false}
$scope.button.c = {clicked: false}
$scope.select = function(button){
var clicked = button.clicked;
$scope.button.a.clicked = false;
$scope.button.b.clicked = false;
$scope.button.c.clicked = false;
button.clicked = !clicked;
};
});
<html ng-app="mySuperApp">
<head>
<meta charset="utf-8">
<title>
Toggle button
</title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
<script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
</head>
<body class="padding" ng-controller="MyCtrl">
<html ng-app="mySuperApp">
<head>
<meta charset="utf-8">
<title>
Toggle button
</title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
<script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
</head>
<body class="padding" ng-controller="MyCtrl">
<button class="button button-primary" ng-model="button.a" ng-click="select(button.a)" ng-class="button.a.clicked?'button-dark':'button-stable'">
A
</button>
<button class="button button-primary" ng-model="button.b" ng-click="select(button.b)" ng-class="button.b.clicked?'button-dark':'button-stable'">
B
</button>
<button class="button button-primary" ng-model="button.c" ng-click="select(button.c)" ng-class="button.c.clicked?'button-dark':'button-stable'">
B
</button>
</body>
</html>
</div>
</body>
</html>