'use strict'; angular.module('pos') .controller('MainCtrl', function ($scope, $timeout, $http) { var webservice = 'api/?a=projects'; $scope.getRandomHex = function (digits) { var rand = Math.random(); return Math.floor(Date.now() / rand).toString(16).substring(2, 2 + digits); }; $scope.projects = []; $scope.newProject = { 'ID': $scope.getRandomHex(8), 'Date': new Date(), 'Description': "Famta Flohmarkt", 'Count': 4, 'PointsOfSale': [ ] }; $scope.generateProject = function () { for (var i = 0; i < $scope.newProject.Count; i++) { $scope.newProject.PointsOfSale[i] = { 'ID': $scope.getRandomHex(6), 'Client': "" }; } $timeout(function () { JsBarcode(".barcode").init(); }, 300); }; $scope.refresh = function () { $http.post(webservice) .then(function (response) { $scope.projects = response.data; }); }; $scope.refresh(); });