I have an angled factory that returns json data. Within a controller I invoke the same to get the data, the point is that invoking the same inside the controller object exists only to use a console.log
, if you assign it to a variable it becomes empty.
Could someone help me?
//Factory
app.factory('dataLoad', function($http, $q) {
return {
getContent: function() {
var deferred = $q.defer();
$http.get('data-json.php')
.success(function(data) {
deferred.resolve(data);
})
.error(function() {
deferred.reject();
});
return deferred.promise;
}
}
});
Controller:
$scope.node = [];
dataLoad.getContent().then(
function(data) {
//Objeto é impresso normalmente
console.log(data);
//nulo
$scope.node = data;
}
);
console.log($scope.node);