获取错误“无法实例化模块{0},原因是:\ n {1}”

时间:2016-01-01 19:57:54

标签: javascript angularjs

我对此感到有点生气。为什么这个脚本在SE中运行但在JSFiddle ???

中不起作用

var myApp = angular.module('myApp', ['myControllers']);

var myControllers = angular.module('myControllers', []);

myControllers
  .controller('MyController', ['$scope', function ($scope) {
    $scope.petameters = 10;
    $scope.lightyears = $scope.petameters / 9.460730472580800;
    $scope.parsecs = $scope.lightyears / 3.2616;
  }]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myApp">
    <div ng-controller="MyController">
      		Petameters:<input type="text" ng-model="petameters"><br/>
          Light years:<input type="text" ng-model="lightyears"><br/>
          Parsecs:<input type="text" ng-model="parsecs"><br/>
    </div>
</body>

JSFiddle:https://jsfiddle.net/dimskraft/wr7kvsy9/5/

代码是复制粘贴的。在JSFiddle版本中,它不会在单元格中显示任何值。

它还会抛出一个异常Uncaught Error: [$injector:modulerr],其中包含未设置占位符的消息Failed to instantiate module {0} due to:\n{1}" ...

1 个答案:

答案 0 :(得分:2)

jsfiddle设置出错。在onLoad事件上执行的脚本

enter image description here

您应该将其更改为"no wrap - in <head>"

enter image description here

并且一切正常

JS fiddle