1

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?

4
  • And what is the output of your TypeScript compiler? Or what is the problem for that matter? Commented Nov 24, 2015 at 13:28
  • My Problem is I don't know how i can write the bottom Part with a TypeScript Class, because of the return Commented Nov 24, 2015 at 14:28
  • github.com/DefinitelyTyped/DefinitelyTyped/blob/master/… - it seems that the return type is IService. If you don't know and don't have time to solve the issue, you can just use any. Commented Nov 24, 2015 at 14:31
  • I want that the class creates the cache and is returning the configured restangular service, like in my js file. I could solve it with a factory method, but i wanted to know if there are other ideas or attempts to solve my question Commented Nov 24, 2015 at 14:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.