I have the following code I'm. I'm looking for the the module for promise and $q in Angular 5 but did not find aany useful detaildetailed info. The code below areis in AngularJS and Javascript. Want
I want to have to transfer this code to using Angular 5 and TypescriptTypeScript. This is a mock service to mock the data:
angular.module('reports.appActivity').factory('AppActiveMockServices', ['$q', function ($q) { var appActivity; function loadappActivity(params) { var deferred = $q.defer(), cancel = function (reason) { deferred.resolve(reason); }; injectappActivity(params); deferred.resolve(appActivity); return { promise: deferred.promise, cancel: cancel }; } function injectappActivity(params) { var total = Math.floor((Math.random() * 100)), someUsage = total - Math.floor((Math.random() * 80)), tempValue, maxIndex = 0, deltaTime=0, daysSelected, timeBegin, timeEnd, d = new Date(), dayInmilliseconds; appActivity = {total: total, items: []}; deltaTime = 24 * 3600 * 1000; // daily timeBegin = (params.timestamp_start).getTime(); timeEnd =(params.timestamp_end).getTime(); daysSelected = Math.round((timeEnd - timeBegin) / 3600/24/1000); if (daysSelected <= 1 ) { maxIndex = 24 ; // one day , resolution is hourly data deltaTime = 3600 * 1000; // hourly dayInmilliseconds = (d.getTime() - (24 * 3600 * 1000)); } else if (daysSelected <= 7) { maxIndex = 7; // 7 days , resolution is daily data dayInmilliseconds = (d.getTime() - (7* 24 * 3600 * 1000)); } else if (daysSelected <= 30) { maxIndex = 30; // 30 days , resolution is daily data dayInmilliseconds = (d.getTime() - (30* 24 * 3600 * 1000)); } else { // custom range maxIndex = daysSelected; // x days , resolution is daily data dayInmilliseconds = (d.getTime() - (daysSelected * 24 * 3600 * 1000)); } for (var index = 0; index < maxIndex; index++) { d.setTime(dayInmilliseconds + (index * deltaTime)); total = Math.floor((Math.random() * 100)); tempValue = Math.floor((Math.random() * 50)); someUsage = (tempValue > total) ? total : (total - tempValue); var item = { 'total': total, 'some_usage': someUsage, 'date': d.toISOString().slice(0, 19) + 'Z' }; appActivity.items.push(item); } } return { loadappActivity: loadappActivity }; } ]); angular.module('reports.appActivity').factory('AppActiveMockServices', ['$q', function ($q) { var appActivity; function loadappActivity(params) { var deferred = $q.defer(), cancel = function (reason) { deferred.resolve(reason); }; injectappActivity(params); deferred.resolve(appActivity); return { promise: deferred.promise, cancel: cancel }; } function injectappActivity(params) { var total = Math.floor((Math.random() * 100)), someUsage = total - Math.floor((Math.random() * 80)), tempValue, maxIndex = 0, deltaTime=0, daysSelected, timeBegin, timeEnd, d = new Date(), dayInmilliseconds; appActivity = {total: total, items: []}; deltaTime = 24 * 3600 * 1000; // daily timeBegin = (params.timestamp_start).getTime(); timeEnd =(params.timestamp_end).getTime(); daysSelected = Math.round((timeEnd - timeBegin) / 3600/24/1000); if (daysSelected <= 1 ) { maxIndex = 24 ; // one day , resolution is hourly data deltaTime = 3600 * 1000; // hourly dayInmilliseconds = (d.getTime() - (24 * 3600 * 1000)); } else if (daysSelected <= 7) { maxIndex = 7; // 7 days , resolution is daily data dayInmilliseconds = (d.getTime() - (7* 24 * 3600 * 1000)); } else if (daysSelected <= 30) { maxIndex = 30; // 30 days , resolution is daily data dayInmilliseconds = (d.getTime() - (30* 24 * 3600 * 1000)); } else { // custom range maxIndex = daysSelected; // x days , resolution is daily data dayInmilliseconds = (d.getTime() - (daysSelected * 24 * 3600 * 1000)); } for (var index = 0; index < maxIndex; index++) { d.setTime(dayInmilliseconds + (index * deltaTime)); total = Math.floor((Math.random() * 100)); tempValue = Math.floor((Math.random() * 50)); someUsage = (tempValue > total) ? total : (total - tempValue); var item = { 'total': total, 'some_usage': someUsage, 'date': d.toISOString().slice(0, 19) + 'Z' }; appActivity.items.push(item); } } return { loadappActivity: loadappActivity }; } ]);