在这种情况下:
<div ng-include='http://cdn.somewebsite.com/templates/home.tpl.html'></div>
网站site.com的cdn子域名通过DNS / CName映射到内容传送网络.
但是,当加载主站点atebsite.com时,它不会渲染模板.我猜内部认为这是一个跨域呼叫.
有没有办法让Angular模板托管在第三方CDN上并与本地域合作?
官方文件说:
By default,the template URL is restricted to the same domain and protocol as the application document. This is done by calling $sce.getTrustedResourceUrl on it. To load templates from other domains or protocols you may either whitelist them or wrap them as trusted values. Refer to Angular’s Strict Contextual Escaping.
和
Please note: The browser’s Same Origin Policy and Cross-Origin Resource Sharing (CORS) policy apply in addition to this and may further restrict whether the template is successfully loaded. This means that without the right CORS policy,loading templates from a different domain won’t work on all browsers.
例:
angular.module('myApp',[]).config(function($sceDelegateProvider) { $sceDelegateProvider.resourceUrlWhitelist([ // Allow same origin resource loads. 'self',// Allow loading from outer templates domain. 'http://cdn.somewebsite.com/templates/**' ]); });
有用的网址:
所以您的问题可能会通过适当的角度设置来解决,但不适用于所有浏览器.