Restangle使用app context不一致

时间:2016-12-20 15:16:46

标签: angularjs restangular

我对Restangular使用我的网站上下文不一致有问题。我的网站运行在example.com/app-name。拨打以下电话时我希望它能点击example.com/app-name/foo

angular.module('myApp').factory('File', File);
File.$inject = [ 'Restangular' ];
function File(Restangular) {
    var service = {
        postFiles : postFiles
    };
    return service;

    function postFiles(files) {
        return Restangular.all('foo').post(files);
    }
}

但是,它会点击example.com/foo

虽然不理想,但我想我现在要设置基本网址来解决这个问题,然后创建一个构建步骤来处理不同的环境应用程序名称。

angular.module('myApp').run(run);
run.$inject = [ 'Restangular' ];
function run(Restangular) {
    Restangular.setBaseUrl('app-name');
}

在此之后,它现在点击example.com/app-name/app-name/foo

我目前解决问题的方法是

Restangular.one('app-name').all('foo').post(files)

哪个有效,但同样需要一些构建任务设置,以使可配置性不理想。

我还尝试将<base>标记设置为以下内容:

<base href="/app-name/" />

请求仍然转到example.com/foo而不是example.com/app-name/foo

在Restangular的设置或使用中是否缺少某些内容?为什么在这两种情况下应用程序上下文的使用方式不同?

0 个答案:

没有答案