xpepermint / angular-ui-switch

On/off switch button for AngularJS. DEPRECATED!
278 stars 125 forks source link

While passing data recieved from an API call, switch on/off not working as expected (While passing "true" and "false"[string values]) #44

Open hmudimi opened 8 years ago

hmudimi commented 8 years ago

angular.module('app', ['uiSwitch'])

.controller('MyController', function($scope) { $http.get("myurl").success(function (data, status, headers, config) {

//Static allocation $scope.enabled = data.enabled; //"false" or "true" $scope.onOff = data.onOff; //"false" or "true" $scope.yesNo = data.yesNo; //"false" or "true" $scope.disabled = data.disabled; //"false" or "true" //I receive so many values from API call like this. //I allocate all params dynamically, Because of this data assigned to $scope.enabled param is "true"(String) not true(boolean). //I have a generic code to assign Api values in scope and perform operations on API values, but now only for this switch I have to check received value and after that I have to proceed, code will be like if(data.enabled == "true") $scope.enabled = true else $scope.enabled = false }) $scope.changeCallback = function() { console.log('This is the state of my model ' + $scope.enabled); }; });

May be I think its not an issue but this implementation will helps all.

ask-khan commented 5 years ago

Used $scope.enable with an object attribute means that $scope.object.enable like this It will worked :)