AngularJS加载模块失败

AngularJS is failing to load module

本文关键字:失败 模块 加载 AngularJS      更新时间:2023-09-26

首先介绍我的环境。我使用的是Windows7、StS IDE和关键的tc服务器谷歌Chrome。

我建立了一个angularJS应用程序。下面是我的index.jsp 的代码

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<!--[if lt IE 7]>      <html lang="en" ng-app="myApp" class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html lang="en" ng-app="myApp" class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html lang="en" ng-app="myApp" class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>My AngularJS App</title>
   <script src="<c:url value="resources/js/angular.min.js"/>"></script>
   <script src="<c:url value="resources/js/angular-route.min.js"/>"></script>
    <script src="<c:url value="resources/js/angular-resource.min.js"/>"></script>
     <script src="<c:url value="resources/js/bootstrap.min.js"/>"></script>
   <script src="<c:url value="app/view1/FormView.js"/>"></script>
   <script src="<c:url value="app/view1/controller.js"/>"></script>
       <script src="<c:url value="app/view1/services.js"/>"></script>
   <script src="<c:url value="app/view2/Form2View.js"/>"></script>
    <script src="<c:url value="app/view2/controller.js"/>"></script>
           <script src="<c:url value="app/view2/service.js"/>"></script>
   <script src="<c:url value="app/js/bootstrap.min.js"/>"></script>
            <script src="<c:url value="app/myApp.js"/>"></script>
  <link rel="stylesheet" href="<c:url value ="resources/css/bootstrap.min.css"/>">
   <link rel="stylesheet" href="<c:url value ="app/view1/app.css"/>">

  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body  data-ng-app= "myApp">
  <ul class="menu">
    <li><a href="#/view1">LookUpCodeStyle</a></li>
    <li><a href="#/view2">AccountMaster</a></li>
  </ul>
  <!--[if lt IE 7]>
      <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
  <![endif]-->
  <div data-ng-view></div>

  <!-- In production use: 
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
  -->

</body>
</html>

当部署在服务器上时,它会抛出以下错误:

Uncaught TypeError: undefined is not a function 
Uncaught TypeError: undefined is not a function 
Uncaught TypeError: undefined is not a function 
Uncaught TypeError: undefined is not a function 
Uncaught Error: No module: ngResource 

但我定义的最大的东西:

<body  data-ng-app= "myApp">

eclipse抛出一个错误:

Cannot find module with name myApp.

我有myApp.js:

angular.module('myApp', [
  'ngRoute',
  'myApp.form',
  'myApp.form2'
]).
config(['$routeProvider', function($routeProvider) {
  $routeProvider.otherwise({redirectTo: '/view1'});
}]);

顺便说一句,它正在加载所有的文件。我登记了网络。如果有任何帮助,我们将不胜感激?

尝试将ngResource添加到myApp模块中。

angular.module('myApp', [
    'ngRoute', 
    'ngResource', 
    'myApp.form',
    'myApp.form2'
 ])

我在Eclipse的AngularJS中遇到了同样的问题:Cannot find module with name MyApp,尽管MyApp已在Angular Explorer中列出。一种解决方法是从MyApp声明中取消捕获config,如下所示:

  var app = angular.module('myApp', [
    'ngRoute',
    'myApp.form',
    'myApp.form2'
  ]);
  app.config(['$routeProvider', function($routeProvider) {
    $routeProvider.otherwise({redirectTo: '/view1'});
   }]);