-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js
34 lines (28 loc) · 850 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
(function(angular) {
'use strict';
// declare a module
var myAppModule = angular.module('myApp', []);
myAppModule.controller('MainController', ['$scope', '$http', function($scope, $http) {
$http({
method: 'GET',
url: "item-types.json"
}).then((types_array) => {
$http({
method: 'GET',
url: "item-list.json"
}).then((items_array) => {
let types = types_array.data.data.reduce( (acc,type) => {
acc[type["ItemTypeId"]] = type["TypeName"];
return acc;
}, {});
$scope.items = items_array.data.data.reduce( (acc,item) => {
let type = types[item["ItemTypeId"]];
if (! (type in acc) )
acc[type] = [];
acc[type].push(item);
return acc;
}, {});
})
});
}]);
})(window.angular);