I am using Buttons (ui.bootstrap.buttons) from UI Bootstrap and I want to link the state of the button with a variable in a array.
This is my controller:
angular.module('test')
.controller('btest',
['$scope',
'$log',
function ($scope, $log) {
$log.info("controller Loaded!");
var checkboxes = [false,false];
$scope.pos1 = checkboxes[0];
$scope.pos2 = checkboxes[1];
}])
This is a part of the HTML:
<div class="row">
<button type="button" class="col-md-1 btn btn-primary" ng-model="pos1" uib-btn-checkbox>B1</button>
<button type="button" class="col-md-1 btn btn-primary" ng-model="pos2" uib-btn-checkbox>B2</button>
</div>
By clicking a button it does not change the value inside checkboxes array but only of his variable.
For example: after the click on "B1" pos1=true
whilecheckboxes[0]=false
.
I can force the update of the vector using an update function like this:
$scope.update = function(index) {
checkboxes[index] = !checkboxes[index];
}
But I think it is not the right way.
Can someone explain me how I can link the state of button with his variable inside checkboxes array.