I have a function to get data from the server through $http.Get
method. after received the data I need to use it on another function. can anyone help me how can I use the data.
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;
});});
After that I have a function for dynamically get the 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;
};
for this function I have to use the $scope.users=data;
value.
Can anyone help me? thanks in advance.