无法实例化模块Angular JS

时间:2014-02-22 05:59:55

标签: angularjs

我是angularjs.i的初学者,写一个小代码。我有三个文件。

的index.html

<!DOCTYPE html>
<html ng-app="docsTransclusionDirective">
<head>
    <title>Hello Dude</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js" type="text/javascript"></script>
    <script src="script.js" type="text/javascript" />
</head>
<body >
<div ng-controller="Ctrl">
   Check out the contents, {{name}} !
</div>
<h1>Hello World</h1>
</body>
</html>

的script.js

angular.module('docsTransclusionDirective', [])
    .controller('Ctrl', function($scope) {
      $scope.name = 'Tobias';
    })
    .directive('myDialog', function() {
      return {
        restrict: 'E',
        transclude: true,
        templateUrl: 'my-dialog.html'
      };
    });

MY-dialog.html

<div class="alert" ng-transclude>
  </div>

它给我错误:

Error: [$injector:nomod] Module 'docsTransclusionDirective' 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.
http://errors.angularjs.org/1.2.13/$injector/nomod?p0=docsTransclusionDirective
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js:78:12
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js:1531:17
    at ensure (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js:1456:38)
    at module (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js:1529:14)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js:3632:22
    at Array.forEach (native)
    at forEach (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js:304:11)
    at loadModules (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js:3626:5)
    at createInjector (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js:3566:11)
    at doBootstrap (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js:1301:20)
http://errors.angularjs.org/1.2.13/$injector/modulerr?p0=docsTransclusionDi…googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.13%2Fangular.js%3A1301%3A20) angular.js:78
(anonymous function) angular.js:78
(anonymous function) angular.js:3660
forEach angular.js:304
loadModules angular.js:3626
createInjector angular.js:3566
doBootstrap angular.js:1301
bootstrap angular.js:1316
angularInit angular.js:1265
(anonymous function) angular.js:20869
trigger angular.js:2355
(anonymous function) angular.js:2626
forEach angular.js:311
eventHandler

任何人都可以告诉我为什么我面临这个错误如何摆脱这个??

1 个答案:

答案 0 :(得分:0)

您的代码工作正常......

http://jsbin.com/rudacaro/2/edit?html,output

确保正确加载script.js

<script>标签不能自动关闭。需要<script src="script.js" type="text/javascript"></script>