2017-09-10 162 views
0

Uncaught Error: [$injector:modulerr] Failed to instantiate module myModule due to: Error: [$injector:nomod] Module 'myModule' 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.無法實例化模塊Mymodule中

<head> 
    <script src="Scripts/angular.js"></script> 
    <script src="Scripts/Script.js"></script> 
    </head> 

    <body ng-controller="myController"> 
    <div> 
     <table> 
      <thead> 
       <tr> 
        <th>Name</th> 
        <th>Likes</th> 
        <th>DisLikes</th> 
        <th>Likes/DisLikes</th> 
       </tr> 
      </thead> 
      <tbody> 
       <tr ng-repeat="technology in technologies"> 
        <td>{{ technology.name }}</td> 
        <td>{{ technology.likes }}</td> 
        <td>{{ technology.dislikes }}</td> 
        <td> 
         <input type="button" value="Like" ng-click="incrementLikes(technology)"> 
         <input type="button" value="Dislike" ng-click="incrementDislikes(technology)"> 
        </td> 
       </tr> 
      </tbody> 
     </table> 
    </div> 

    </body> 
</html> 




var app = angular.module("myModule", []) 



      app.controller("myController", function($scope){ 
        var technologies = [{name:"C#", likes:0, dislikes:0}, 
        {name:"ASP.NET", likes:0, dislikes:0}, 
        {name:"SQL Server", likes:0, dislikes:0}, 
        {name:"Angular JS", likes:0, dislikes:0},]; 

        $scope.technologies = technologies; 

        $scope.incrementLikes = function(technology){ 
         technology.likes++; 
        } 

        $scope.incrementDislikes = function(technology){ 
         technology.dislikes++; 
        } 


     }); 
+0

我們不能幫你,除非你發佈的script.js文件,以及... – Gal

+0

它已經下面給出 –

回答

0

只需添加ng-app="myModule"到HTML,

<body ng-app="myModule" ng-controller="myController"> 

DEMO

var app = angular.module("myModule", []) 
 
app.controller("myController", function($scope){ 
 
var technologies = [{name:"C#", likes:0, dislikes:0}, 
 
        {name:"ASP.NET", likes:0, dislikes:0}, 
 
        {name:"SQL Server", likes:0,dislikes:0}, 
 
        {name:"Angular JS", likes:0, dislikes:0},]; 
 
$scope.technologies = technologies; 
 
$scope.incrementLikes = function(technology){ 
 
     technology.likes++; 
 
} 
 
$scope.incrementDislikes = function(technology){ 
 
      technology.dislikes++; 
 
} 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<body ng-app="myModule" ng-controller="myController"> 
 
    <div> 
 
     <table> 
 
      <thead> 
 
       <tr> 
 
        <th>Name</th> 
 
        <th>Likes</th> 
 
        <th>DisLikes</th> 
 
        <th>Likes/DisLikes</th> 
 
       </tr> 
 
      </thead> 
 
      <tbody> 
 
       <tr ng-repeat="technology in technologies"> 
 
        <td>{{ technology.name }}</td> 
 
        <td>{{ technology.likes }}</td> 
 
        <td>{{ technology.dislikes }}</td> 
 
        <td> 
 
         <input type="button" value="Like" ng-click="incrementLikes(technology)"> 
 
         <input type="button" value="Dislike" ng-click="incrementDislikes(technology)"> 
 
        </td> 
 
       </tr> 
 
      </tbody> 
 
     </table> 
 
    </div> 
 
    </body>

+1

謝謝..它的工作 –

2

您還沒有確定NG-應用= 「MyModule的」 在你的HTML模板。

要麼定義它在HTML或身體標記,然後它應該開始工作。

+0

已經嘗試..不工作 –