为什么我在JSFiddle中找不到错误模块?
问题描述:
我宣布这个模块:为什么我在JSFiddle中找不到错误模块?
angular.module('dashboard', [])
.controller('dashboardController', ['$scope',
function ($scope) {
$scope.data = "555";
}]);
这里是视图:
<div ng-app="dashboard" data-role="page" id="layersProperty" data-add-back-btn="true" >
<div ng-controller="dashboardController">
{{data}}
</div>
</div>
这里是FIDDLE。
在控制台中我得到这个错误:
Error: [$injector:nomod] Module 'dashboard' 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.
任何想法,为什么我得到上述错误?
答
基本上你的代码看起来不错,顺便说一下它的工作检查Plnkr。
检查你的代码(你有角?),或者只是张贴您的全部代码。
代码Plnkr:
<!DOCTYPE html>
<html>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<div ng-app="dashboard" ng-controller="dashboardController">
{{ data }}
</div>
<script>
angular.module('dashboard', [])
.controller('dashboardController', ['$scope',
function($scope) {
$scope.data = "555";
}
]);
</script>
</body>
</html>
答
这是由于您已经在设置的jsfiddle的JavaScript负载类型。当您使用onLoad
时,JSFiddle会将您的javascript包装在$(window).load(function(){});
区块中。这意味着注册您的Angular应用程序的angular.module()
代码在DOM被处理之后才会运行。所以Angular试图找到尚未创建的dashboard
模块。
http://jsbin.com/qekezayipa/edit?html,js,output – Shyju
确实很奇怪。您完全相同的代码,从相同的位置加载angular.js,在plnkr正常工作:http://plnkr.co/edit/NHqBPkItZiNsqhJ8beG7?p=preview –
在的jsfiddle,改变的JavaScript的负载类型是'不包 - 在
'或者'不循环 - 在'而不是onLoad'的'。这是一个JSFiddle的事情,以及它如何与Angular协同工作。 – Lex