lundi 2 octobre 2017

Bootstrap switch start state

I'm using bootstrap-switch and I have a problem with start state, it's always false. I have this HTML code

<div data-ng-repeat="accessory in accessories"
    data-ng-if="accessory.type == accessoryType.SWITCH">
    <div id="test6">
        <span style="margin-right: 5px;"> </span> <input
            type="checkbox" name="accessory" data-ng-init="setAccessory(accessory.id)"
            data-ng-model="accessory.value"
            data-ng-attr-id=""
            data-ng-attr-topic="" bootstrap-switch>
    </div>
</div>

In js file I have

$scope.accessories = response.data.result;
angular.forEach($scope.accessories, function(value, key) {
    if ($scope.accessories[key].type == $scope.accessoryType.SWITCH){
$('input[name=accessory'+$scope.accessories[key].id+']').bootstrapSwitch('state', $scope.accessories[key].value, true);                         

I've also tried with init but it still doesn't work (I read about put id into external div and for example $("test6").bootstrapSwitch('state') works returning true)

$scope.setAccessory = function(id){
        $("test6").bootstrapSwitch('state', true, true);
    }

but If I change the state it doesn't work. How can I fix it? I hoped it worked simply with the model, but I can't set the initial state. Thanks




Aucun commentaire:

Enregistrer un commentaire