一致地获取错误:$ injector:当我加载我的应用程序时,nomod模块不可用

时间:2017-07-22 14:10:35

标签: angularjs

我认为这与我的文件订购方式有关,但我无法弄清楚哪些是导致问题的。

angular.module('app')
.controller('langCtrl', function($scope, languageService){
  $scope.submit = function(model) {
    console.log(model);
    languageService.analyzeDocument(model)
  }
});
<html lang="en" ng-app="app" class="no-js"> <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>WIT</title>
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="images/computer.ico"/>
  <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">

  <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="app.css">
</head>
<body ng-controller="langCtrl">
  <div class="header">
    RecommendHER
  </div>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.min.js"></script>
  <script src="app.js"></script>
  <script src="languageService.js"></script>
  <script src="langCtrl.js"></script>
</body>
</html>

我将index.html文件和我的控制器放在代码段中。我还在app.js和控制器文件的保存级别上有一个服务。这是代码:

angular.module('app')
.service('languageService', function($resource) {
  var apiUrl = 'http://xxx.compute-1.amazonaws.com';

 var languageResource = $resource(apiUrl + {}, {
 analyzeDocument: {
   method: 'POST',
   url: apiUrl + '/analyze_document?file=:text'
 },
 analyzeWord: {
  method: 'POST',
  url: apiUrl + '/recommend?word=":word"'
}
 });

  return {
    analyzeDocument: function(data) {
       return languageResource.analyzeDocument({data:text}).$promise;
     },
      analyzeWord: function(data) {
       return languageResource.analyzeWord({data:word}).$promise;
     }
   };
 });

这是我的app.js文件:

angular.module('app', [

]);

2 个答案:

答案 0 :(得分:0)

您需要向模块添加空依赖项

angular.module('app',[])

修改

更改index.html中的顺序,使模块首先加载,

<script src="app.js"></script>
<script src="languageService.js"></script>
<script src="langCtrl.js"></script>

答案 1 :(得分:0)

您是否已使用两个参数定义了'app'模块:

angular.module('app', []).run(function() {});

一个参数版本期望app已经存在,以便将事物作为模块的一部分包含在内。

另外,请确保首先加载app.js文件。