I am just getting started with angular and saw that you can define a factory to use in multiple controllers.
I have the below code, which is returning my result in the 'success' method fine. But not outside of the function.
I have a feeling its to do with async, but I'm not too sure how to go forward with it, if it is that.
Any help would be appreciated, so thanks in advanced.
var abyssApp = angular.module('abyssApp', []);
abyssApp.factory('abyssData', function($http) {
var result,
products = $http.get('http://abyss.local/products.php');
products.success(function(data) {
result = angular.fromJson(data);
console.log('success: ', result); // object with data in
});
console.log(result); // undefined
});
abyssApp.controller('ItemListCtrl', function($scope, abyssData) {
$scope.items = abyssData;
console.log('abyssData: ', abyssData); // undefined
});