这肯定是一个新手问题,但我似乎无法弄清楚这个简单的模块启动(JSFiddle)有什么问题:
var myApp = angular.module('myApp', []);
我收到一条错误消息,指出“模块‘myApp’不可用!”。有谁知道为什么这不起作用?
最佳答案
这是因为(至少在 fiddle 中)脚本是在 window.onload
上运行的,因此在 DOM 中看到应该有一个名为 的模块之前,angular 无法找到该模块>我的应用程序
。
之前(在头脑中):
window.onload = function() {
angular.module(...)
}
但它必须是:
angular.module(...)
即。不等到文档完全加载,因此在 Angular 看到它应该引导模块 myApp
之前创建模块。
关于angularjs-module - 角度模块不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20002300/