angular-ui-switch icon indicating copy to clipboard operation
angular-ui-switch copied to clipboard

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

Open hmudimi opened this issue 9 years ago • 1 comments

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.

hmudimi avatar May 30 '16 11:05 hmudimi

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

ask-khan avatar May 31 '19 07:05 ask-khan