Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue May 30, 2016 · 1 comment

Comments

@hmudimi
Copy link

hmudimi commented May 30, 2016

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 hmudimi changed the title While passing data recieved from an API call, switch on/off not working as expected (While passing "true" and "false"[string]) While passing data recieved from an API call, switch on/off not working as expected (While passing "true" and "false"[string values]) May 30, 2016
@ask-khan
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants