2017-08-07 84 views
-4

ncaught错误:[$ injector:modulerr]无法实例化模块myApp,原因如下: 错误:[$ injector:nomod]模块'myApp'不可用!您拼错了模块名称或忘记加载模块名称。如果注册模块确保您指定依赖关系作为第二个参数。

+0

我们需要更多代码来评估这一点。您是否加载了定义应用程序的.js文件(angular.module('myApp',[]);'?您是否定义了它? – Brian

+1

https://stackoverflow.com/help/how-to-ask – Brian

+0

https ://codepen.io/ahmedsamirbek/pen/xLqPXz –

回答

0

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

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

此外,为了让您的codepen工作,我不得不修复的角度导入:

+0

它的工作原理...谢谢你 –

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> 

相关问题