Why I get error module not available in JSFiddle?

2019-06-27 04:02发布

I declare this module:

 angular.module('dashboard', [])
    .controller('dashboardController', ['$scope',
            function ($scope) {
                $scope.data = "555";
            }]);

And here is view:

<div ng-app="dashboard" data-role="page" id="layersProperty" data-add-back-btn="true" >
    <div ng-controller="dashboardController">
            {{data}}
    </div>
</div>

And here is FIDDLE.

In console I get this error:

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.

Any idea why I get error above?

3条回答
霸刀☆藐视天下
2楼-- · 2019-06-27 04:50

Basically your code looks good and by the way its working check it Plnkr .

check your code (did you include angular?) or just post your full code.

code in 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>
查看更多
唯我独甜
3楼-- · 2019-06-27 04:54

No issue with your code, since you are adding external scripts you just need to change

Javascript settings -> Load type -> Wrap in <Head> enter image description here

查看更多
劳资没心,怎么记你
4楼-- · 2019-06-27 04:55

This is due to the javascript Load Type you have set on JSFiddle. When you use onLoad, JSFiddle will wrap your javascript in a $(window).load(function (){}); block. This means the angular.module() code that registers your Angular app will not run until after the DOM has been processed. So Angular tries to find a dashboard module that has not been created yet.

查看更多
登录 后发表回答