自定义指令受阻 [英] Custom directive blocked
问题描述
我已经定义了一个自定义的指令,像这样的:
.directive('行',[功能(){
返回{
限制:'E',
templateUrl:铬://mailtowebmails/content/resources/directives/row.htm
};
}])
但是当我尝试使用它,我得到这个错误:
错误:[$ SCE:insecurl]从URL阻止加载资源不被容许$ sceDelegate政策网址:铬://mailtowebmails/content/resources/directives/row.htm
TRY 0
我试过santizing是这样的:
的.config([
'$ compileProvider',
功能($ compileProvider)
{
$ compileProvider.aHrefSanitizationWhitelist(/ ^ \\ S *(文件系统:镀铬):/);
}
])
但它不是固定的。
这是一个插件这样的路径,我的文件在文件系统中。
TRY 1
我也试过:
VAR ANG_APP = angular.module('mailtowebmails',[])
的.config(['$ sceDelegateProvider',函数($ sceDelegateProvider){ $ sceDelegateProvider.resourceUrlWhitelist(['自我',新的RegExp('铬')]); }])
我得到这个错误,那么:
错误:[$喷油器:modulerr]未能实例由于模块mailtowebmails:
[$喷油器:modulerr]未能实例由于模块$ sceDelegateProvider:
[$喷油器:NOMOD]模块'$ sceDelegateProvider不可!你要么拼写错误的模块名称,或忘了加载它。如果
块引用>TRY 2
我也试过这个作为@Tribute推荐,但它没有工作:
VAR ANG_APP = angular.module('mailtowebmails',[])
.directive('行',[功能(){
返回{
限制:'E',
templateUrl:铬://mailtowebmails/content/resources/directives/row.htm
};
}])
.controller('BodyController',['$范围,$ SCE',函数($范围,$ SCE){ $ scope.trustSrc =功能(SRC){
返回$ sce.trustAsResourceUrl(SRC);
};
解决方案您尝试1的方法应该工作。然而正则表达式已被改变。
的.config(['$ sceDelegateProvider',函数($ sceDelegateProvider){ $ sceDelegateProvider.resourceUrlWhitelist(['自我','铬://mailtowebmails/**/*.html']);}])
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); };
解决方案You "Try 1" approach should work. However the regex has to be changed.
.config(['$sceDelegateProvider', function($sceDelegateProvider) { $sceDelegateProvider.resourceUrlWhitelist(['self', 'chrome://mailtowebmails/**/*.html']); }])
这篇关于自定义指令受阻的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!