的延续FO这个问题导致this question,但得到的答复是同时适用于:
我决定去与本地stradegy有两个原因:
- 没有额外的XML请求开销。
- 当资源不存在时,404消息不会监视控制台日志。
services.js
factory('Views', function($location,$route,$routeParams,objExistsFilter) {
var viewsService = {};
var views = {
subdomain1:{
'home.html':'/views/subdomain1/home.html'
},
subdomain2:{
},
'home.html':'/views/home.html',
};
viewsService.returnView = function() {
var y = $route.current.template;
var x = $location.host().split(".");
return (x.length>2)?(objExistsFilter(views[x[0]][y]))?views[x[0]][y]:views[y]:views[y];
};
viewsService.returnViews = function() {
return views;
};
return viewsService;
}).
controllers.js
controller('AppController', ['$scope','Views', function($scope, Views) {
$scope.$on("$routeChangeSuccess",function($currentRoute, $previousRoute){
$scope.page = Views.returnView();
});
}]).
filters.js
filter('objExists', function() {
return function (property) {
try {
return property;
} catch (err) {
return null
}
};
});
您的模板url看起来只是您的索引文件路径的相对路径。所以要更改域名(小心同源策略),您必须使这些路径为绝对路径,可能使用常量来配置它们。 –
@xmltechgeek对不起,但我想你可能跳过了子域指向同一个doc根的部分--- SOP与它无关。这里的问题是,我需要一种检测域的方法,而不是拦截“templateUrl”并将其更改为不同的子域。 –
不知道你会用默认的角度路由器做到这一点。你应该可以使用angular-ui团队的ui-router(https://github.com/angular-ui/ui-router)中的templateProvider来做到这一点。请参阅https://github.com/angular-ui/ui-router/wiki#alternative-ways-to-set-the-template。 –