【问题标题】:Angularjs module isn't loading correctlyAngularjs 模块未正确加载
【发布时间】:2015-01-10 21:41:49
【问题描述】:

请帮助了解问题所在。我对 AngularJS 很陌生,也许我错过了一些东西。 这是我的简单 HTML:

<!DOCTYPE html>
<html>
    <script type="text/javascript" src="angular.js"></script>
    <script type="text/javascript" src="app.js"></script>
</head>
<body ng-app="myApp">

</body>
</html>

JS

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

以及所有时间错误:
未捕获的错误:[$injector:modulerr] 无法实例化模块 myApp,原因如下: 错误:[$injector:nomod] 模块“myApp”不可用!您要么拼错了模块名称,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。

【问题讨论】:

    标签: javascript angularjs


    【解决方案1】:

    我认为您可能想调用该立即函数:

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

    否则,里面的 JavaScript 永远不会运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-04
      • 2011-08-30
      • 1970-01-01
      • 1970-01-01
      • 2016-03-27
      • 2018-08-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多