我在使用 Angular Route 时遇到了奇怪的问题。我正在尝试从跨域调用模板。除非我注意到当我将其他域放入路由中时,它不会发送请求。
需要明确的是,这不是 CORS 问题,而是根本没有发送请求的问题。我的代码,我从 example.com 调用 example2.com:
app.config(['$routeProvider', function($routeProvider) {
var app_url = "http://templates.example2.com/";
$routeProvider
// route for the home page
.when('/', {
templateUrl : app_url + '/pages/home',
controller : 'mainController'
})
.when('/home', {
templateUrl : app_url + '/pages/home',
controller : 'homeController'
})
// route for the about page
.when('/about', {
templateUrl : app_url + '/pages/about',
controller : 'aboutController'
});
}]);
如何强制 Angular 发送请求?
最佳答案
这可能是对 Angular 的疏忽,因为它根本不会抛出任何错误,但您必须将域列入白名单,因为它使用 $sce.getTrustedResourceUrl(tpl);
https://docs.angularjs.org/api/ng/provider/ $sceDelegateProvider#resourceUrlWhitelist
关于javascript - Angular 路由跨域调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43038254/