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

后端 未结 6 1630
清酒与你
清酒与你 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条回答
  •  旧时难觅i
    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:

    
    
        
    
        
    
    
    

    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.

提交回复
热议问题