My services.js file is structured like this:
var app = angular.module('starter.services', [])
.factory('Studies',function($http,$filter){
var studies = [];
$http.get("studies.json").success(
function(data){
//studies = data;
angular.copy(data, studies);
}
);
single_object = $filter('filter')(studies, function (d) {return d.nodeRef === "56e3382b-9a76-48ee-9c14-907e71b7a184";})[0];
console.log(single_object);
return {
all: function(){
return studies;
}
};
})
Within the code above, I am making a get request for a json file that contains objects with attributes, one of them being "nodeRef". My goal is to filter out a specific object based on its nodeRef match. However, when checking the console, it returns "undefined". This may be happening because the console log gets called before the json file is fully loaded. Can someone please help provide a solution?