简体   繁体   English

AngularJS找不到$ locationProvider模块

[英]AngularJS can't find $locationProvider module

I keep getting the following error when I try to use $locationProvider. 当我尝试使用$ locationProvider时,我不断收到以下错误。 Do I need to import the module somehow? 我是否需要以某种方式导入模块?

Error: $injector:unpr
Unknown Provider
Unknown provider: $locationProviderProvider <- $locationProvider

This is my code: 这是我的代码:

var myApp = angular.module('myApp', [
    'duScroll', 'duParallax', 'angularFileUpload', 'ngRoute'
    ]);

myApp.config(function ($locationProvider) {
    $locationProvider.html5Mode(true).hashPrefix('');
});

As you can see, the code you posted works by itself : 正如你所看到的,你的代码被发布作品本身

Given your error message, I think you tried to inject $locationProvider in a different function, so it tries to find $locationProviderProvider . 给定您的错误消息,我认为您尝试将$ locationProvider注入另一个函数中,因此它尝试查找$locationProviderProvider

Look for a callback function that is not passed to config that injects $locationProvider . 查找未传递到注入$locationProvider config的回调函数。 You'll want to inject $location instead. 您将需要注入$location

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM