那麼,我終於找到了解決方案。創建如下面的自定義裝載機:
配置在如下的app.config部
app.factory('customLoader',
function ($http, $q, $timeout, $rootScope) {
return function (options) {
var deferred = $q.defer();
var filename = $rootScope.name;
console.log('../translate/' + filename + '/' + options.key + '.json');
$http({
method:'GET',
url: '../translate/' + filename + '/' + options.key + '.json'
}).success(function (data) {
deferred.resolve(data);
}).error(function() {
deferred.reject(options.key);
});
$timeout(function (data) {
deferred.resolve(data);
}, 2000);
return deferred.promise;
}
}):
$translateProvider.useLoader('customLoader', {});
並設置從控制器的文件名(路徑),如下:
$rootScope.name = $scope.country;