【发布时间】:2014-10-21 12:31:50
【问题描述】:
我正在使用 angular.js,并且我有一个使用 Web 服务的模块
/* Rest WS Config */
RestangularProvider.setBaseUrl(ENVL.apiEndpoint+'/ig-web/services');
效果很好。
我想使用相对的方式来设置我的基本 URL(因为我不能为每个环境提供特定的配置)所以我尝试了:
RestangularProvider.setBaseUrl('/ig-web/services');
RestangularProvider.setBaseUrl('./ig-web/services');
但这没有用。
有什么想法吗?
下面是完整的模块文件
'use strict';
angular.module('env.config', [])
.constant('ENVL', {
'name': 'development local',
'apiEndpoint': 'http://localhost:8080'
})
.constant('DEVT', {
'name': 'development server',
'apiEndpoint': 'http://domain.dev'
})
.constant('INT', {
'name': 'integration server',
'apiEndpoint': 'http://domain.int'
})
.constant('REC', {
'name': 'recette server',
'apiEndpoint': 'http://domain.rec'
});
var app = angular.module('saisinesApp', [
'ngAnimate',
'ngResource',
'ui.bootstrap',
'toaster',
'angular.css.injector',
'angularFileUpload',
'dialogs',
'ui.router.state',
'ajoslin.promise-tracker',
'cgBusy',
'restangular',
'ngGrid',
'xeditable',
'env.config',
'saisinesAppFilters'])
.constant('_', window._)
.constant('jsPDF',window.jsPDF);
app.config(function ($stateProvider, $urlRouterProvider, RestangularProvider,ENVL) {
/* Rounting config*/
$urlRouterProvider.when('/home', '/home/search');
$stateProvider
.state('auth', {
url: '/',
templateUrl: 'src/auth/authentication.html',
controller: 'AuthCtrl'
})
.state('auth-by-url', {
url: '/:token',
templateUrl: 'src/auth/authentication.html',
controller: 'AuthCtrl'
})
.state('home', {
abstract: true,
url: '/home',
templateUrl: 'src/common/header.html',
controller: 'HeaderCtrl'
})
.state('home.search', {
url: '/search',
templateUrl: 'src/search/search.html',
controller: 'SearchCtrl'
})
.state('home.search-by-siren', {
url: '/search/:siren',
templateUrl: 'src/search/search.html',
controller: 'SearchCtrl'
})
.state('home.create', {
url: '/create',
templateUrl: 'src/create/create.html',
controller: 'CreateCtrl'
})
.state('home.recap', {
url: '/recap',
templateUrl: 'src/recap/recap.html'
});
$urlRouterProvider.otherwise('/');
/* Rest WS Config */
//RestangularProvider.setBaseUrl(ENVL.apiEndpoint+'/ig-web/services');
RestangularProvider.setBaseUrl('./ig-web/services');
});
app.run([
'$rootScope', '$state', '$stateParams', function($rootScope, $state, $stateParams) {
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
}
]);
【问题讨论】:
-
您使用的是什么版本的 Restangular? RestangularProvider.setBaseUrl('/ig-web/services');是一个正确的电话。我从未见过使用 './' 作为 url,但您提到的第一个选项应该可以正常工作。您是否收到错误消息?它在什么方面不起作用?
标签: angularjs restangular