JumpLink / angular-toggle-switch

AngularJS Toggle Switch
http://jumplink.github.io/angular-toggle-switch/
MIT License
68 stars 37 forks source link

ng-change and ng-click not working #33

Closed nvanoost closed 7 years ago

nvanoost commented 7 years ago

I have 4 switches on one page, all in the $scope.settings model. All the switches have an ng-change='changeShopSettings()' attribute, so every time a switch is changed I expect that my settings will be saved. But the ng-change looks not working. Even when I try ng-change="console.log('test')", I get nothing in my console.

<toggle-switch ng-model="settings.showShop" on-label="Aan" off-label="Uit" ng-change="changeShopSettings()"></toggle-switch>

Controller

$scope.settings = {};
$scope.changeShopSettings = function(){
        console.log("changeShopSettings");
        $http({
            method: 'POST',
            url: '/winkelier/shop-settings',
            data: {
                shopId: $scope.shopId,
                showShop: $scope.settings.showShop,
                showAllProducts: $scope.settings.showAllProducts,
                sendProducts: $scope.settings.sendProducts,
                isDropShipper: $scope.settings.isDropShipper
            }
        }).then(function successCallback(response){
            console.log("settings saved", response);
        }, function errorCallback(response){
            console.log("ERROR", response);
        });
    }

Tried also with al $scope.watchCollection("settings"), but that doesn't work too.