Angularjs $location正在抛出类型错误:无法读取属性';更换';未定义的

Angularjs $location正在抛出类型错误:无法读取属性';更换';未定义的,angularjs,Angularjs,我刚刚开始学习angularjs,我正在学习一个教程,但我在chrome控制台中不断遇到这个错误 TypeError: Cannot read property 'replace' of undefined at trimEmptyHash (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.js:10564:13) at $LocationProvider.$get (https://ajax.googleapis.c

我刚刚开始学习angularjs,我正在学习一个教程,但我在chrome控制台中不断遇到这个错误

TypeError: Cannot read property 'replace' of undefined
at trimEmptyHash (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.js:10564:13)
at $LocationProvider.$get (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.js:11374:9)
at Object.invoke (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.js:4185:17)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.js:4003:37
at getService (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.js:4144:39)
at Object.invoke (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.js:4176:13)
at extend.instance (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.js:8454:21)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.js:7700:13
at forEach (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.js:331:20)
at nodeLinkFn (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.js:7699:11) 
这是我的index.html文件

<!DOCTYPE html>
<html lang="en">
<head>
    <base href="file:///home/chintan/anges/" />
    <meta charset="UTF-8">
    <title>angular tutorial</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.js"></script>
    <script type="text/javascript" src="main.js"></script>
</head>

<body>
    <div ng-app="myOpenRecipes" ng-controller="recipeCtrl">
        <h1>{{searchTerm}}</h1>
    </div>
</body>

</html>

如果我删除$location,它将非常有效。可能有什么问题?

无法复制。。。。您的代码在这里运行良好。不过,你的
base
看起来很可疑。怀疑您使用的是本地文件而不是本地主机web服务器它在plnkr中工作正常,但在chrome和Firefox中都会中断使用本地服务器而不是文件协议谢谢,它现在正在使用本地服务器此答案可能会帮助您:
window.MyOpenRecipes = angular.module('myOpenRecipes', []);

MyOpenRecipes.config(function($locationProvider) {
    $locationProvider.html5Mode(true);
});

MyOpenRecipes.controller('recipeCtrl', ['$scope', '$location', function($scope, $location) {
    $scope.searchTerm = "Pasta"
}]);