I'm trying to get data from database and assign it to a dynamic scope variable with a function but it doesn't assign the data to the dynamic variable at first attempt. Can anyone help?
This is my dynamicScope function;
$scope.dynamicScope= function(name, data){
var modelScope = $parse(name);
modelScope.assign($rootScope, data);
};
and here is postService function;
$scope.postService = function(scopeName, sentData){
$http.post($scope.serviceLink, sentData)
.success(function (data, status) {
console.log("Fetched data: " + data);
$scope.dynamicScope(scopeName, data);
})
.error(function (errData, status) {
console.log("Error: "+errData);
});
};
When I call postService as
$scope.postService("userInfo", loginData);
It prints data from the postService but it gives an error when I want to print it after the previous line like here console.log($scope.userInfo[0].user_name);
it says $scope.userInfo is undefined. But it fetches previous data in the second attempt. Thanks in advance.