Angularjs Angular.js如何在app.config中使用location.search?

Angularjs Angular.js如何在app.config中使用location.search?,angularjs,Angularjs,我正在尝试设置$compileProvider.debugInfoEnabled(false);除非将?debug=true的查询参数传递到url中。但是,$location在app.config函数中不起作用 myApp.config(['$compileProvider', '$location', function ($compileProvider, $location) { if (!$location.search().debug || $location.search()

我正在尝试设置$compileProvider.debugInfoEnabled(false);除非将?debug=true的查询参数传递到url中。但是,$location在app.config函数中不起作用

myApp.config(['$compileProvider', '$location',
function ($compileProvider, $location) {

    if (!$location.search().debug || $location.search().debug === false) {
        $compileProvider.debugInfoEnabled(false);
    }
}
]);
我收到一个错误'error:[$injector:unpr]未知提供程序:$location'


你知道怎么做吗?

你只能在配置块中插入提供程序和常量。不要在配置中使用
$location
,试着在
.run()中使用它,或者改用
$locationProvider

表单:

配置块-在提供程序注册和配置阶段执行。只有提供程序和常量才能注入配置块。这是为了防止在完全配置服务之前意外实例化服务

$location是一项服务,没有提供程序。直接访问底层浏览器位置对象的唯一方法是。如果需要,可以使用$window帮助进行单元测试:

if (!$window.location.search.debug || $window.location.search.debug === false) {
    $compileProvider.debugInfoEnabled(false);
}

$locationProvider不允许访问浏览器的位置对象-是@bbrown您是对的。我的意思是你想要$locationProvider:D