restangular icon indicating copy to clipboard operation
restangular copied to clipboard

Restangular.service, then Restangular.setBaseUrl

Open peterzebird opened this issue 9 years ago • 1 comments

Hello,

I don't know if this is a bug or a bad use of Restangular from me.

I have a Restangular service inside angular factory. To simplify, let's say factory is like this (I have some more functions on Factory but not important here)

function powerNodeFactory (Restangular) {
        return Restangular.service('<somePath>');
    }
module.factory('powerNodeModel', ['Restangular', powerNodeFactory]);

Then I can do followings with my factory

powerNodeModel.getList();
powerNodeModel.one(<someID>);

My problem is : After this factory has been instanciated, I want to change Restangular base URL (from user's choice). So I tried somewhere

Restangular.setBaseUrl('<someDifferentPath>');

But when using the Factory again, it is still using the first Path.

If I try to change base url before using Factory once, it is using the new path as intended.

I guess it's because Factory has been instanciated with this path on the first place and Restangular does not calculate url again after that.

Is it working as intended ? Then should I just forget to use service and Factory if I want to be able to change baseUrl at anytime from anywhere ?

Thank you for your help.

peterzebird avatar Sep 15 '15 14:09 peterzebird

powerNodeFactory.setBaseUrl()?

ashgibson avatar Jan 09 '17 07:01 ashgibson