【问题标题】:Failed to instantiate module app due to in AngularJS?由于在 AngularJS 中无法实例化模块应用程序?
【发布时间】:2017-08-17 02:17:34
【问题描述】:

我正在尝试制作一个 AngularJS 应用程序。但是我收到了这个错误:

由于

无法实例化模块应用程序

这是我的代码:

<html>
<head><title>New Version!</title>
</head>
<body ng-app="app">
<div ng-controller="appcontr">
    <ul>
        <li>A new XSLT engine is added: Saxon 9.5 EE, with a namecense (thank you Michael Kay!)</li>
        <li>XSLT 3.0 support when using the new Saxon 9.5 EE engine!</li>
        <li>Preview your result as HTML when doctype is set to HTML (see this example)</li>
        <li>Preview your result as PDF when doctype is set to XML and your document starts with root element of XSL-FO.
            Apache FOP is used to generate the PDF
        </li>
        <li>Added some namenks to useful XSLT sites</li>
    </ul>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.5/angular.js"/>


<script>
    angular.module('app', []).controller('appcontr', appcontr)
    function appcontr($scope) {
        $scope.name = 'dd'
    }

</script>

</body>
</html>

【问题讨论】:

  • 实例化失败有什么原因吗?
  • 由于什么?错误消息包含有关问题的信息,并且在问题中被省略了。它可以通过做某事来解决。
  • Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to: Error: [$injector:nomod] Module 'app' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
  • 由于未能关闭第一个 &lt;script&gt; 标记,angular.module 代码将被忽略。

标签: javascript angularjs


【解决方案1】:

它工作正常,只需按如下方式关闭您的脚本引用:

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.5/angular.js">
</script>

演示

angular.module('app', []).controller('appcontr', appcontr)
    function appcontr($scope) {
        $scope.name = 'dd'
    }
<html>
<head><title>New Version!</title>
</head>
<body ng-app="app">
<div ng-controller="appcontr">
<h1> {{name}}</h1>
    <ul>
        <li>A new XSLT engine is added: Saxon 9.5 EE, with a namecense (thank you Michael Kay!)</li>
        <li>XSLT 3.0 support when using the new Saxon 9.5 EE engine!</li>
        <li>Preview your result as HTML when doctype is set to HTML (see this example)</li>
        <li>Preview your result as PDF when doctype is set to XML and your document starts with root element of XSL-FO.
            Apache FOP is used to generate the PDF
        </li>
        <li>Added some namenks to useful XSLT sites</li>
    </ul>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.5/angular.js">
</script>
</body>
</html>

【讨论】:

  • 能否请您提供更多信息,请提供 plunker
  • 哪个参考?
  • @user5711656 检查演示,它的 angular.js 参考
猜你喜欢
  • 1970-01-01
  • 2019-08-23
  • 2018-09-10
  • 2017-06-17
  • 2017-12-11
  • 1970-01-01
  • 2014-05-30
  • 2014-06-04
  • 1970-01-01
相关资源
最近更新 更多