Angular JS Uncaught Error: [$injector:modulerr]

后端 未结 15 1784
攒了一身酷
攒了一身酷 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 02:03

    Make sure that the variable that holds your angular.module is structured correctly.

    This will fail with "Uncaught Error: [$injector:modulerr]":

    var angApp = angular.module("angApp");
    

    This works:

    var angApp = angular.module("angApp", []);
    

    It's a sneaky one since the error message doesn't point to one thing in particular (Thus the wide variety of answers). Additionally, most js linters won't catch the particulars. Keep at it!

    0 讨论(0)
  • 2020-12-09 02:06

    Make sure you're function is wrapped in a closure, complete with the extra () at the end:

    (function(){                                                                     
    
        var app = angular.module('myApp', []);                                     
    
    
    })();  
    
    0 讨论(0)
  • 2020-12-09 02:09

    In development I recomend you to use not minified distributives: And all errors become more informative! Instead angular.min.js use angular.js

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