无法使用 templateUrl 在 cordova 中加载外部模板

unable to load external templates in cordova with templateUrl

Cordova 4.0 版部署到 Windows8.1 阻止外部模板

        .when('/', {
            controller: 'login',
            templateUrl: 'http://ip-address/templates/login.html',
            resolve: resolver('login')
        })

备注: 这不是 InAppBrowser 应用程序。 index.html 是本地的,router.js 也是本地的 config.xml 有

<access origin="*" />

所以应该不会出现任何跨域问题。

我不知道这是否有帮助,所以我只是发表评论(请参阅有问题的评论)。我的 index.html 文件中有这个,而我需要访问 templates.com 上的模板(例如):

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval' *.azure-mobile.net http://localhost:1337 http://ajax.aspnetcdn.com">

潜在问题似乎是跨源问题,但通过以下解决方法解决了这个问题。基本理论是 $http.get 能够解析 text/html 或 application/json.

app.run(....)

            var allTemplates = [
                'my-template-1.html',
                'login-template.html',
                'logout-template.html',
                'unsupportedversion.html'
            ];

            allTemplates.forEach(function(template){
                $http.get('http://example.com/templates/'+template).success(function (t) {
                    $templateCache.put('templates/'+template, t);
                }).error(function(data, status, headers, config) {
                    $rootScope.appErrors.push(template+' failedToLoad');
                });
            });