I am using the follow code to get json object and bind it to the $scope
WORKING CODE:
$http({
url: '/Home/GetJson',
method: "GET",
params: {
clientID: cId
}
}).success(function (data) {
$scope.members = data.members;
})
It works .. what I would like to do is get the results into a var data
then add it to the $scope.
FAILING CODE :
var data = $http({
url: '/Home/GetJson',
method: "GET",
params: {
clientID: cId
}
}).success(function (data) {
return data.members;
})
$scope.members = data;
When I look at $scope.members, it is empty in the failing code because $scope.members is empty when it is filled (js is event based).
How can I wait till json returns > then var = data > then $scope.members = data ?
WORKING CODE
I used Javascript callback functions as below
Call my main function
DoLogin($scope, $http, email, password, AssingMemberToScope);
function DoLogin($scope, $http, email, password, callback) {
$http({
url: '/Home/GetJson',
method: "GET",
params: {
clientID: cId
}
}).success(function (data) {
callback($scope, data); //<----- Call Back occurs
})
}
//--Call-back Function working and code is separated --/
function AssingMemberToScope($scope, data) {
if (data.msg) {
$('.loading').hide();
$scope.member = data.member;
} else {
$('.loading').hide();
$('#msg').show();
}
}