未捕获错误:[$ injector:modulerr]无法实例化模块 myModule由于:错误:[$ injector:nomod]模块'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 :(得分:2)
您尚未在html模板中定义ng-app =“myModule”。
在html或body标签中定义它然后它应该开始工作。
答案 1 :(得分:0)
只需将ng-app="myModule"
添加到您的HTML
<body ng-app="myModule" ng-controller="myController">
<强>样本强>
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>