My dilemma arises from fetching data from the server using the $http.Get
method. Once I have received this data, I need to utilize it in another function. Any assistance on how to achieve this would be greatly appreciated.
var app = angular.module("app", []);
app.factory('itemsFactory', function ($http) {
var factory = {};
factory.getItems = function () {
return $http.get('.//davidstrans.json')
};
return factory;
});
app.controller('UsersTransController', function ($scope, itemsFactory) {
itemsFactory.getItems().success(function (data) {
$scope.users = data;
});});
Following this step, I also have a requirement for dynamically retrieving types:
function groupBy(arr, key) {
var newArr = []
, types = {}
, newItem, i, j, cur;
for (i = 0, j = arr.length; i < j; i++) {
cur = arr[i];
if (!(cur[key] in types)) {
types[cur[key]] = {
type: cur[key]
, data: []
};
newArr.push(types[cur[key]]);
}
types[cur[key]].data.push(cur);
}
return newArr;
};
In order to implement this function effectively, I must integrate the value of $scope.users=data;
. Can anyone guide me through this process? Thank you in advance.