Angular 脚本中的控制器错误 - [$injector:modulerr]
Controller error in Angular Script - [$injector:modulerr]
我不确定控制器语法。我不断收到[$injector:modulerr]错误,这让我相信这是控制器在播放,但除此之外我就迷路了。我目前的主要目标是尝试"获取"并显示来自 couchdb 数据库的所有结果。
<div ng-app="guestBook">
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js">
</script>
<script>
var guestBook = angular.module('guestBook', ['ngRoute'])
guestBook.controller('CouchController', ['$scope', '$http', '$get', function ($scope, $http, $get) {
// View everything in database
$scope.view = function () {
var json = {};
var url = "https://sophia.iriscouch.com/guestbook/_all_docs";
$get({
url: url,
method: 'GET',
data: json,
dataType: "jsonp",
}).success(function (json, status, headers, config) {
console.log(json);
})
};
// Creating a new instance on couchDB
$scope.submit = function () {
var entry = {
"Name": $scope.name,
"Comment": $scope.comment
};
console.log(entry);
var timestamp = Math.round(new Date().getTime() / 1000);
var url = 'https://sophia.iriscouch.com/guestbook/' + timestamp;
console.log(url);
$http({
url: url,
method: 'PUT',
data: entry,
dataType: "json",
withCredentials: true,
headers: {
'Authorization': auth_hash("sophia", "Einstein1")
}
}).success(function (data, status, headers, config) {
console.log(data);
}).error(function (data, status, headers, config) {
console.log(headers);
console.log(config);
});
}
function auth_hash(username, password) {
var str = window.btoa(username + ":" + password);
return 'Basic' + str;
}
}]);
</script>
<form ng-controller="CouchController">
<p>
<input type="text" ng-model="comment">
</p>
<p>
<input type="text" ng-model="name">
</p>
<p>
<button ng-click="submit()">Add</button>
</p>
<p>
<button ng-click="view()">show</button>
</p>
</form>
指定依赖ngRoute
模块,例如
angular.module('guestBook', ['ngRoute'])
但是您没有添加angular-route.js
脚本文件。添加该文件将解决此问题。
这是 ngRoute 模块的 CDN
添加后,代码应该是这样的,
<div ng-app="guestBook">
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.6/angular-route.js"></script>
....
相关文章:
- 错误:$injector:modulerr模块错误(我的第一个SPA应用程序)
- 错误:$injector:modulerr加载图像时模块处于角度
- ng路由injectore:modulerr中出错[$injector:modulerr]http://errors.a
- 未捕获的错误: [$injector:modulerr] http ..(使用纯 HTML)
- 未捕获的错误:使用 ng-repeat 时出现 [$injector:modulerr]
- 未捕获的错误: [$injector:modulerr] - 角度 ng-include
- Error $injector:modulerr AngularJs
- Angularjs未捕获错误:迁移到V1.3时出现[$injector:modulerr]
- $injector:modulerr将自定义模块注入Angular应用程序
- 未捕获错误:[$injector:modulerr](新手)
- AngularJS错误:$injector:modulerr我的浏览器窗口中出现模块错误
- 获取未捕获错误:anuglar.js中的[$injector:modulerr]
- Angular应用程序无法安装,原因是出现错误:[$injector:modulerr]
- AngularJS - $injector:modulerr 模块错误在 angular.js:36.
- 未捕获的错误: [$injector:modulerr] 无法实例化模块 toastr
- Angularjs Error: [$injector:modulerr] 'ngRoute'
- 角度 JavaScript 缩小导致错误:$injector:modulerr 模块错误
- Injector:modulerr in the config (newbie)
- Angular js 未捕获错误:[$injector:modulerr] 匿名函数
- AngularJS : 未捕获错误: [$injector:modulerr] 使用 angularJS 的更新版本时