Skip to main content
added 27 characters in body
Source Link
David Walschots
  • 12.7k
  • 5
  • 39
  • 59

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 }; } ]); 

I have the following code I'm looking for the the module for promise and $q in Angular 5 but not find a useful detail info. The code below are in AngularJS and Javascript. Want to have to transfer this code to using Angular 5 and Typescript. This is 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 }; } ]); 

I have the following code. I'm looking for the the module for promise and $q in Angular 5 but did not find any useful detailed info. The code below is in AngularJS and Javascript.

I want to have to transfer this code to Angular 5 and TypeScript. 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 }; } ]); 
This question is about converting to angular; therefore other tags are not needed
Link
David Walschots
  • 12.7k
  • 5
  • 39
  • 59
added 312 characters in body
Source Link
 angular.module('reports.appActivity').factory('AppActiveMockServices', 

['$q', function ($q) {

 ['$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 }; } 

]);

 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   };  }  ]); 
edited tags
Link
Estus Flask
  • 226.4k
  • 79
  • 478
  • 620
Loading
added 1921 characters in body
Source Link
Loading
Source Link
Loading