1

I have defined a custom directive like this:

.directive('row', [function() {
    return {
        restrict: 'E',
        templateUrl: 'chrome://mailtowebmails/content/resources/directives/row.htm'
    };
}])

But when I try using it I get this error:

"Error: [$sce:insecurl] Blocked loading resource from url not allowed by $sceDelegate policy. URL: chrome://mailtowebmails/content/resources/directives/row.htm

TRY 0

I tried santizing like this:

.config( [
    '$compileProvider',
    function( $compileProvider )
    {
        $compileProvider.aHrefSanitizationWhitelist(/^\s*(filesystem:chrome):/);
    }
])

But its not fixing it.

This is for an addon so the path to my file is on the filesystem.

TRY 1

I also tried:

var ANG_APP = angular.module('mailtowebmails', [])
    .config(['$sceDelegateProvider', function ($sceDelegateProvider) {

        $sceDelegateProvider.resourceUrlWhitelist(['self', new RegExp('chrome')]);

    }])

I get this error then:

Error: [$injector:modulerr] Failed to instantiate module mailtowebmails due to: [$injector:modulerr] Failed to instantiate module $sceDelegateProvider due to: [$injector:nomod] Module '$sceDelegateProvider' is not available! You either misspelled the module name or forgot to load it. If

TRY 2

I also tried this as @Tribute recommended but it didnt work:

var ANG_APP = angular.module('mailtowebmails', [])
    .directive('row', [function() {
        return {
            restrict: 'E',
            templateUrl: 'chrome://mailtowebmails/content/resources/directives/row.htm'
        };
    }])
    .controller('BodyController', ['$scope', '$sce', function($scope, $sce) {

        $scope.trustSrc = function(src) {
            return $sce.trustAsResourceUrl(src);
        };
Noitidart
  • 35,443
  • 37
  • 154
  • 323
  • http://stackoverflow.com/questions/21292114/external-resource-not-being-loaded-by-angularjs – Deepak Ingole Aug 19 '15 at 05:33
  • Thanks @TributetoAPJKalamSir but that didn't work :( I updated the topic with the code i tried. I dont have a controller, this is a direcitve. – Noitidart Aug 19 '15 at 05:35
  • Why are you loading through `chrome://` protocol ? Just use absolute path `/mailtowebmails/content/resources/directives/row.htm' – Mike Vranckx Aug 19 '15 at 06:20

1 Answers1

1

You "Try 1" approach should work. However the regex has to be changed.

.config(['$sceDelegateProvider', function($sceDelegateProvider) {

  $sceDelegateProvider.resourceUrlWhitelist(['self', 'chrome://mailtowebmails/**/*.html']);

}])
Bharat
  • 943
  • 7
  • 9
  • 1
    Np. Out of curiosity, you were getting "[$injector:modulerr] Failed to instantiate module $sceDelegateProvider due to:" with "Try 1" approach. What was the root cause for that error? – Bharat Aug 19 '15 at 07:11
  • I'm not sure @Bharat :( I'm new to angular Im using this to make a Firefox addon heres my github repo: https://github.com/Noitidart/MailtoWebmails/blob/master/resources/scripts/app.js#L142 – Noitidart Aug 19 '15 at 07:13
  • Ok. That error was weird. And all the best for your addon! – Bharat Aug 19 '15 at 07:16