1

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

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):/);
});

But the chrome console says:

"angular.js:68 Uncaught Error: [$injector:unpr] Unknown provider: $compileProviderProvider <- $compileProvider"

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:

angular.js:13550 TypeError: $compile.aHrefSanitizationWhitelist is not a function

Community
  • 1
  • 1
user1272965
  • 2,814
  • 8
  • 29
  • 49

1 Answers1

10

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):/);
  }
]);
Oliver
  • 519
  • 5
  • 11
  • Thanks but no luck. I get "angular.js:68 Uncaught Error: [$injector:modulerr] Failed to instantiate module mytodoApp due to: TypeError: $compileProvider.urlSanitizationWhitelist is not a function" (the only thing I changed in your suggestion was myModule to mytodoApp (which is my app name). – user1272965 May 27 '16 at 21:05
  • did you try "aHrefSanitizationWhitelist" ? Because the urlSanitizationWhiteList Method got removed and splitted to imgSrcSanitizationWhitelist and aHrefSanitizationWhitelist – Oliver May 27 '16 at 21:08
  • Thanks. That did the trick. My real problem was the syntax chaining the config around my other configs. – user1272965 May 27 '16 at 21:12
  • 1
    3rd `module` argument is `config` function, so separate `config` is not necessary. – Estus Flask May 27 '16 at 21:12