How to get async value for restangular parameter?

I need to get a value from the async service to add as a parameter to every other call. CasService.getProxyTicket () - call $ http ...

I have the following code: -

myFactories.factory('myFactory', [
    'Restangular'
    , 'casService'
    , function (Restangular
        , casService) {
        return Restangular.withConfig(function (config) {
            config.setBaseUrl('https://host:port/somecontext/rest');
            config.addFullRequestInterceptor(function (element
                , operation
                , route
                , url
                , headers
                , params
                , httpConfig) {

... What do I need to do here?

                casService.getProxyTicket(url).then(function(st){
                    console.log('proxyTicket = ' + st.data.ticket);
                });

                params.ticket = ?????? <= st.data.ticket

...

                return {
                    element: element
                    , headers: headers
                    , params: params
                    , httpConfig: httpConfig
                }
            });
        }).service('myCollection');
    }]
);

... thanks in advance!!!!

+4
source share
1 answer

Ok, I don’t understand what comes from the background of the backend developer ...

This / should NOT be done that way! I tried to make a call to get a proxy ticket synchronously .... DON'T DO IT!

What I did was change the order of the code ...

function readItem(id) {
    var endpoint = myFactory.one(id);
    return casService.getProxyTicket(endpoint.getRestangularUrl())
        .then(function (response) {
            return endpoint.get({ticket: response.data.proxyTicket});
        }).then(function (response) {
            return response.plain();
        });
}

... works like a charm!

0
source

All Articles