unable to load external templates in cordova with templateUrl

434 Views Asked by At

Cordova version 4.0 deploying to Windows 8.1 prevents external templates

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

Notes: This is not a InAppBrowser application. index.html is local and so is the router.js config.xml has

<access origin="*" />

So any Cross Domain issue should not arise.

2

There are 2 best solutions below

0
On BEST ANSWER

Underlying problem seems Cross Origin Issue but solved this with following workaround. The basic theory is that $http.get is able to resolve text/html or application/json.

In 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');
                });
            });
1
On

I don't know if this will help, so I'm just commenting (see comments under question). I have this in my index.html file, whereas I needed to access templates on templates.com (as an example):

<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">