我收到以下错误:
Failed to instantiate module ContactsApp due to: TypeError: undefined is not a function
当我在app.js中注释掉html5mode时,错误消失了,当我导航到/联系人时,views / list.html模板没有加载。我对角度很新,所以我觉得我只是忽略了一些简单的事情,而且我不太确定如何解决问题。
app.js:
angular.module('ContactsApp', ['ngRoute'])
.config(function ($routeProvider, $locationProvider) {
$routeProvider
.when('/contacts', {
controller: 'ListController',
templateUrl: 'views/list.html'
});
$locationProvider.html5mode(true);
});
HTML:
<html ng-app="ContactsApp">
<head>
<title>Contacts</title>
<base href="/" />
<link rel="stylesheet" href="lib/bootstrap/dist/css/bootstrap.min.css" />
</head>
<body>
<div class="container">
<div class="page-header">
<h1>Contacts</h1>
</div>
<div class="row">
<div class="col-sm-12" ng-view></div>
</div>
</div>
<script src="lib/jquery/dist/jquery.min.js"></script>
<script src="lib/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="lib/angular/angular.min.js"></script>
<script src="lib/angular-route/angular-route.min.js"></script>
<script src="src/app.js"></script>
<script src="src/controller.js"></script>
</body>
</html>
答案 0 :(得分:2)
这是html5Mode(大写'M')。
angular.module('ContactsApp', ['ngRoute'])
.config(function ($routeProvider, $locationProvider) {
$routeProvider
.when('/contacts', {
controller: 'ListController',
templateUrl: 'views/list.html'
});
$locationProvider.html5Mode(true);
});