I am trying to convert my RestAngular Services to Typescript. I occured a problem with the configuration part, that you can do with restangular.
Im a bit confused how i can achieve the same functionality with a typescript class.
My AngularJS Code
(function () {
'use strict';
angular
.module('myApp.ui.services')
.factory('statData', statData);
statData.$inject = ['Restangular', '$angularCacheFactory'];
/* @ngInject */
function statData(Restangular, $angularCacheFactory) {
var statDataCache = $angularCacheFactory('statDataCache');
statDataCache .setOptions({
capacity: 10,
recycleFreq: 60000,
cacheFlushInterval: 3600000,
deleteOnExpire: 'aggressive',
storageMode: 'localStorage'
});
return Restangular.withConfig(function (RestangularConfigurer) {
RestangularConfigurer.setDefaultHttpFields({cache: statDataCache });
RestangularConfigurer.setBaseUrl('data/');
});
}
})();
TypeScript
export class StatDataService{
static $inject = ['Restangular', '$angularCacheFactory'];
private _statDataCache: any;
/*@ngInject*/
constructor(public restNg: ng.IRestangularService, public $angularCacheFactory: ng.ICacheFactoryService) {
this._statDataCache = $angularCacheFactory('statDataCache');
this._statDataCache.setOptions({
capacity: 10,
recycleFreq: 60000,
cacheFlushInterval: 3600000,
deleteOnExpire: 'aggressive',
storageMode: 'localStorage'
});
}
}
The Problem is this specific part
return Restangular.withConfig(function (RestangularConfigurer) {
RestangularConfigurer.setDefaultHttpFields({cache: statDataCache });
RestangularConfigurer.setBaseUrl('data/');
});
How can i include this into my TypeScript class?
return
IService
. If you don't know and don't have time to solve the issue, you can just useany
.