Angular gives same generic error

时间:2017-04-06 17:08:54

标签: angularjs

When I try to run angular code , it always gives this generic error message though it is nor problem with module api or name. For example, in this case, I put name value pairs separated in object with semi colon in config method. After changing to comma, it is fine now. But it does not tell exact cause is in config not in module name. How do I find exact cause?

Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [$injector:nomod] Module 'myApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

1 个答案:

答案 0 :(得分:0)

这是一个常见的错误。当模板中声明的ng-app名称与脚本中使用的名称不同时会发生这种情况,例如:

<强>的index.html

<html lang="en" ng-app="app">
<head>
  <meta charset="utf-8">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js"></script>
  <script src="script.js"></script>
</head>

<body>
</body>
</html>

<强>的script.js

angular.module('app', []);

angular.module('myApp') // <-- ERROR OCCURS HERE, it should be 'app'
.controller('ExampleController', ['$scope', '$http', function($scope, $http) {

// controller code here

}]);