未捕获的错误:[$ injector:modulerr]无法实例化模块

时间:2017-08-07 15:39:17

标签: angularjs

ncaught错误:[$ injector:modulerr]由于以下原因导致无法实例化myApp模块: 错误:[$ injector:nomod]模块' myApp'不可用!您要么错误拼写了模块名称,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。

2 个答案:

答案 0 :(得分:1)

您创建了一个匿名函数,但从不调用它:

(function() {
  var myApp = angular.module("myApp", []);
  myApp.controller("FirstController", function($scope) {
    $scope.Name = "Ahmed";
  });
})() // add the ();

此外,为了使您的codepen工作,我必须修复角度导入:

<script 
    src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.4/angular.js" 
    type="text/javascript">
</script>

答案 1 :(得分:0)

<html ng-app="myApp">
<head>
    <meta charset="utf-8" />
    <title>angularJs</title>
    <script src="angular-1.6.4/angular.js" type="text/javascript"> </script>

</head>

<body  >
    <div ng-controller="FirstController">
        <span>{{Name}}</span>
    </div>
    <script>
        (function(){
            var myApp = angular.module('myApp', []);         
            myApp.controller("FirstController", function ($scope) {
               $scope.Name="Ahmed"; 
            });

        });

    </script>
</body>