【问题标题】:AngularJs (ngResource ) : Error: [$injector:modulerr] http://errors.angularjs.org/1.3.15/AngularJs(ngResource):错误:[$injector:modulerr] http://errors.angularjs.org/1.3.15/
【发布时间】:2015-06-03 19:25:48
【问题描述】:

我想将 ngResource 与 HTTP 一起使用,但出现此错误:

错误:[$injector:modulerr] http://errors.angularjs.org/1.3.15/$injector/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"
      }
    }
]

有人有什么想法吗?

【问题讨论】:

  • 错字,ngRessource 是什么?额外的s
  • @PSL 附加的东西是script 标签角没有正确关闭

标签: angularjs ngresource


【解决方案1】:

ngRessource 中的错字应该是ngResource

var myApp = angular.module('myApp', ['ngResource']);

您还制作了 Angular js script 引用自关闭,这是完全错误的。您应该正确关闭角度脚本标签。往下看。

<script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">
</script>

【讨论】:

  • @carine 对你有帮助吗..?
  • 是的,最后我在脚本链接上找到了错误,我用&lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular-resource.min.js"&gt;&lt;/script&gt; 替换了&lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular-resource.min.js"/&gt;,现在它可以工作了,非常感谢:)
  • 是的,当然,但是请问我的要求如何?
【解决方案2】:

您提供给应用模块定义的依赖项中有错字。 将var myApp = angular.module('myApp', ['ngRessource']); 更改为var myApp = angular.module('myApp', ['ngResource']);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-01
    • 1970-01-01
    相关资源
    最近更新 更多