Why I get error module not available in JSFiddle?

泪湿孤枕 提交于 2019-12-10 15:39:04

问题


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?


回答1:


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

Javascript settings -> Load type -> Wrap in <Head>




回答2:


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.




回答3:


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>


来源:https://stackoverflow.com/questions/44890420/why-i-get-error-module-not-available-in-jsfiddle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!