I use the following code to get a json object and bind it to $ scope
WORKING CODE:
$http({ url: '/Home/GetJson', method: "GET", params: { clientID: cId } }).success(function (data) { $scope.members = data.members; })
This works .. what I would like to do is get the results in var data , and then add it to the $ scope.
FAULT 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 error codes because $ scope.members is empty when it is full (js is an event).
How can I wait until json returns> then var = data> and then $ scope.members = data?
WORK 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);
// - Callback function and code are separated - /
function AssingMemberToScope($scope, data) { if (data.msg) { $('.loading').hide(); $scope.member = data.member; } else { $('.loading').hide(); $('#msg').show(); } }