Question

I have the following code:

<span ng-include="getHeaderTemplate()"></span>

getHeaderTemplate() returns "templates/header/prospection.html"

however, I get the following error:

Error: [$sce:insecurl] Blocked loading resource from url not allowed by $sceDelegate policy.  URL: templates/header/prospection.html
http://errors.angularjs.org/1.2.9/$sce/insecurl?p0=templates%2Fheader%2Fprospection.html
    at http://localhost/piquick/laravel/public/vendor/angular-1.2.9.js:78:12
    at Object.getTrusted (http://localhost/piquick/laravel/public/vendor/angular-1.2.9.js:12739:17)
    at Object.sceParseAsTrusted (http://localhost/piquick/laravel/public/vendor/angular-1.2.9.js:13168:22)
    at Scope.$digest (http://localhost/piquick/laravel/public/vendor/angular-1.2.9.js:11800:40)
    at Scope.$apply (http://localhost/piquick/laravel/public/vendor/angular-1.2.9.js:12061:24)
    at http://localhost/piquick/laravel/public/vendor/angular-1.2.9.js:1302:15
    at Object.invoke (http://localhost/piquick/laravel/public/vendor/angular-1.2.9.js:3710:17)
    at doBootstrap (http://localhost/piquick/laravel/public/vendor/angular-1.2.9.js:1300:14)
    at bootstrap (http://localhost/piquick/laravel/public/vendor/angular-1.2.9.js:1314:12)
    at angularInit (http://localhost/piquick/laravel/public/vendor/angular-1.2.9.js:1263:5) 

The Url is on the same server (it's a local URL), so I don't understand why I get this error.

Here's the doc about $sce

http://docs.angularjs.org/api/ng.$sce#resourceurlpatternitem

Was it helpful?

Solution

That looks like AngularJS' Strict Contextual Escaping (SCE) mode has blocked loading a resource from an "insecure" URL.

Their docs state: "The browser's Same Origin Policy and Cross-Origin Resource Sharing (CORS) policy apply that may further restrict whether the template is successfully loaded. (e.g. neither cross-domain requests won't work on all browsers nor file:// requests on some browsers)"

Try wrapping the template url with a call like:

$sce.trustAsUrl('templates/header/prospection.html')

Here's more info.

OTHER TIPS

Works for me the same configuration. Can you please give us plnkr example?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top