compileProvider避免不安全的链接

compileProvider避免不安全的链接

本文介绍了使用$ compileProvider避免不安全的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以轻松注入$ scope,$ location和$ routeProvider之类的东西,为什么$ compileProvider与众不同?

I have no trouble injecting things like $scope and $location and $routeProvider, why is $compileProvider different?

基于此答案,我了解我必须指示angular不要为某些链接添加前缀(在我的情况下为sms),但我无法在项目中应用答案.它说我应该添加这个:

Based on this answer, I understand that I have to instruct angular to not prefix certain links (sms in my case), but I can't apply the answer in my project. It says I should add this:

angular.module('myModule', [], function ($compileProvider) {
    $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|file):/);
});

但是Chrome控制台会说:

But the chrome console says:

"provider-provider"一词使我认为服务的真实名称只是$ compile(并且在"provider"后缀上添加了angular:

That "provider-provider" thing made me think that the real name of the service is just $compile (and that angular is tacking on the "provider" suffix:

angular.module('myModule', [], function ($compile) {
    $compile.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|file):/);
});

但是随后,我猜想我得到了:

But then, predictably, I guess, I get:

推荐答案

这是因为您必须将其添加为配置:

That's because you have to add it as a config:

angular.module('myModule').config(['$compileProvider',
  function($compileProvider) {
    $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|file):/);
  }
]);

这篇关于使用$ compileProvider避免不安全的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 23:04