Consider code (Angular 1.2 RC3):
main.config(['$routeProvider', '$sce', function($routeProvider, $sce) {
$routeProvider.when('/', { templateUrl: $sce.trustAsResourceUrl('bla-bla.html'), controller: "App.Controllers.BlaBla" });
$routeProvider.otherwise({ redirectTo: '/' });
}]);
It will throw an exception because services are not allowed during config and i'm using "$sce" (Strict Contextual Escaping) service here.
How to use SCE in "config" method? What is possible solutions to this problem?
Angular has $sceProvider
service whereby in privileged contexts, directives and code will bind to the result of $sce.getTrusted(context, value)
rather than to the value directly.
Directives use $sce.parseAs
rather than $parse
to watch attribute bindings, which performs the $sce.getTrusted
behind the scenes on non-constant literals.
Configuration blocks - get executed during the provider registrations and configuration phase. Only providers and constants can be injected into configuration blocks. This is to prevent accidental instantiation of services before they have been fully configured.
Run blocks - get executed after the injector is created and are used to kickstart the application. Only instances and constants can be injected into run blocks. This is to prevent further system configuration during application run time.
So, now $sceProvider is an inbuilt service, you can't inject your own service, or built-in services like $http into config().
Use run() instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With