Angular JS Uncaught Error: [$injector:modulerr]

后端 未结 15 1782
攒了一身酷
攒了一身酷 2020-12-09 01:08

I am having a problem with Angular JS receiving an error : Uncaught Error: [$injector:modulerr]. My JS-file looks

angular.module(\'MyApp\', [\'ngRoute\']);
         


        
相关标签:
15条回答
  • 2020-12-09 01:43

    ok if you are getting a Uncaught Error: [$injector:modulerr] and the angular module is in the error that is telling you, you have an duplicate ng-app module.

    0 讨论(0)
  • 2020-12-09 01:44

    I had also same issue, I have just removed following line of code from BundleConfig.cs file and my code is working fine.

    BundleTable.EnableOptimizations = true;

    0 讨论(0)
  • 2020-12-09 01:47

    The problem was caused by missing inclusion of ngRoute module. Since version 1.1.6 it's a separate part:

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular-route.min.js"></script>
    
    var app = angular.module('myapp', ['ngRoute']);
    

    This is getting reference from: AngularJS 1.2 $injector:modulerr David answer

    0 讨论(0)
  • 2020-12-09 01:48

    Just throwing this in in case it helps, I had this issue and the reason for me was because when I bundled my Angular stuff I referenced the main app file as "AngularWebApp" instead of "AngularWebApp.js", hope this helps.

    0 讨论(0)
  • 2020-12-09 01:49

    Try adding:

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

    and:

    angular.module('MyApp', ['ngRoute','ngResource']);
    function TwitterCtrl($scope,$resource){
    }
    

    You should call angular.module only once with all dependencies because with your current code, you're creating a new MyApp module overwriting the previous one.

    From angular documentation:

    Beware that using angular.module('myModule', []) will create the module myModule and overwrite any existing module named myModule. Use angular.module('myModule') to retrieve an existing module.

    0 讨论(0)
  • 2020-12-09 01:50

    Try adding this:

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-resource.min.js"></script>
    
    0 讨论(0)
提交回复
热议问题