I am trying to set the $compileProvider.debugInfoEnabled(false); except if a query param of ?debug=true is passed into the url. However $location does not work in the app.config function.
myApp.config(['$compileProvider', '$location',
function ($compileProvider, $location) {
if (!$location.search().debug || $location.search().debug === false) {
$compileProvider.debugInfoEnabled(false);
}
}
]);
I get an error 'Error: [$injector:unpr] Unknown provider: $location'
Any idea how this can be done?
Form the documentation:
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.
$location is a service, and has no provider. The only way to get to the underlying browser's location object is directly. You can use $window to help with unit testing, if you need that:
if (!$window.location.search.debug || $window.location.search.debug === false) {
$compileProvider.debugInfoEnabled(false);
}
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