2017-04-06 15 views
-1

當我嘗試運行角碼時,它總是給出這個通用錯誤消息,儘管它不是模塊api或名稱的問題。例如,在這種情況下,我將名稱值對用分號分隔在配置方法中的分號中。改爲逗號後,現在就好了。但它並沒有確切的原因是在config中,而不是在模塊名稱中。我如何找到確切的原因?Angular給出了相同的通用錯誤

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

後:當你的模板聲明的ng-app的名字從你的腳本中使用的一個不同,比如它發生你的代碼看到的問題 – Sajeetharan

+0

@chinni我的回答是否幫助你解決了你的問題? –

回答

0

這是一個常見錯誤。

的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 

}]);