AngularJS: Uncaught Error: [$injector:modulerr] Failed to instantiate module?

后端 未结 6 1478
清酒与你
清酒与你 2020-11-30 03:26

I am new to AngularJS and working my way through some documents and tutorials to learn. My question is in reference to Egghead\'s video series, this video in particular, dem

相关标签:
6条回答
  • 2020-11-30 03:49

    it turns out that I got this error because my requested module is not bundled in the minification prosses due to path misspelling

    so make sure that your module exists in minified js file (do search for a word within it to be sure)

    0 讨论(0)
  • 2020-11-30 03:57

    For people who find this old posting on the web by searching for the error message, there is another possible cause of the problem.

    You could just have a typo in your call to the script, even if you have already done the things described in the other excellent answer. So check to make sure you can used the right spelling in your script tags.

    0 讨论(0)
  • 2020-11-30 04:03

    I had to change the js file, so to include "function()" at the beginning of it, and also "()" at the end line. That solved the problem

    0 讨论(0)
  • 2020-11-30 04:08

    Try using No Wrap - In Head or No wrap - in body in your fiddle:

    Working fiddle: http://jsfiddle.net/Q5hd6/

    Explanation:

    Angular begins compiling the DOM when the DOM is fully loaded. You register your code to run onLoad (onload option in fiddle) => it's too late to register your myApp module because angular begins compiling the DOM and angular sees that there is no module named myApp and throws an exception.

    By using No Wrap - In Head, your code looks like this:

    <head>
    
        <script type='text/javascript' src='//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.js'></script>
    
        <script type='text/javascript'>
          //Your script.
        </script>
    
    </head>
    

    Your script has a chance to run before angular begins compiling the DOM and myApp module is already created when angular starts compiling the DOM.

    0 讨论(0)
  • 2020-11-30 04:12

    You have to play with JSFiddle loading option :

    set it to "No wrap - in body" instead of "onload"

    Working fiddle : http://jsfiddle.net/zQv9n/1/

    0 讨论(0)
  • 2020-11-30 04:13

    For people having the same error with a similar code:

    $(function(){
        var app = angular.module("myApp", []); 
        app.controller('myController', function(){
    
        });
    });
    

    Removing the $(function(){ ... }); solved the error.

    0 讨论(0)
提交回复
热议问题