我想在HTTP中使用ngResource,但我有这个错误:
错误:[$ injector:modulerr] http://errors.angularjs.org/1.3.15/ $注射器/ modulerr P0 = MyApp来&安培; P1 =%5B%24injector%3Anomod%5D%20
这是我的代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Angular ngResource</title>
<script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular-resource.min.js"></script>
<script>
var myApp = angular.module('myApp', ['ngResource']);
myApp.factory('UserService',['$resource', function ($resource) {
return $resource('http://jsonplaceholder.typicode.com/users/:user',{user: "@user"});
}]);
myApp.controller('produitsCtrl', function($scope, $http,UserService) {
$scope.users = UserService.query();
});
</script>
</head>
<body>
<div ng-app="myApp" >
<div ng-controller="produitsCtrl">
<ul>
<li ng-repeat="x in users">
{{ x.name + ', ' + x.username }}
</li>
</ul>
</div>
</div>
</body>
</html>
我的json文件是: http://jsonplaceholder.typicode.com/users
[
{
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "Sincere@april.biz",
"address": {
"street": "Kulas Light",
"suite": "Apt. 556",
"city": "Gwenborough",
"zipcode": "92998-3874",
"geo": {
"lat": "-37.3159",
"lng": "81.1496"
}
},
"phone": "1-770-736-8031 x56442",
"website": "hildegard.org",
"company": {
"name": "Romaguera-Crona",
"catchPhrase": "Multi-layered client-server neural-net",
"bs": "harness real-time e-markets"
}
},
{
"id": 2,
"name": "Ervin Howell",
"username": "Antonette",
"email": "Shanna@melissa.tv",
"address": {
"street": "Victor Plains",
"suite": "Suite 879",
"city": "Wisokyburgh",
"zipcode": "90566-7771",
"geo": {
"lat": "-43.9509",
"lng": "-34.4618"
}
}
]
任何人都有想法吗?
答案 0 :(得分:0)
您提供给app模块定义的依赖项中存在拼写错误。
将var myApp = angular.module('myApp', ['ngRessource']);
更改为var myApp = angular.module('myApp', ['ngResource']);
。
答案 1 :(得分:0)
ngRessource
中的错误应该是ngResource
var myApp = angular.module('myApp', ['ngResource']);
你也使角js script
引用自闭,这是完全错误的。你应该正确关闭角度脚本标签。看下面。
<script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">
</script>