In my angularjs service I want an array to be filled as follows:
var results = [
{id: 1, name: 'John'},
{id: 2, name: 'Jane}
]
I want to do this by calling an API. So far I have written this:
function getDataFromAPI() {
$http.get('foo.com/bar.json').then(function(data){
console.log( data.data.employees);
});
}
var results = getDataFromAPI();
When I call results, in my chrome dev tools it will display the results from the json file, but I don't know how to populate the results array.
How can I fill the array?