script.js
AngularJS
var app = angular.module('TEDU', []);
app.controller('handleEventController', ['$scope', function ($scope) {
var technologies = [{
Name: "C#",
Likes: 0,
Minus: 0,
Dislikes: 0
},
{
Name: "ASP.NET",
Likes: 0,
Minus: 0,
Dislikes: 0
},
{
Name: "SQL Server",
Likes: 0,
Minus: 0,
Dislikes: 0
},
{
Name: "AngularJS",
Likes: 0,
Minus: 0,
Dislikes: 0
}
];
$scope.technologies = technologies;
$scope.increaseLike = function (technology) {
technology.Likes++;
technology.Minus = technology.Likes - technology.Dislikes;
}
$scope.increaseDislike = function (technology) {
technology.Dislikes++;
technology.Minus = technology.Likes - technology.Dislikes;
}
}]);
handle_event.html
AngularJS
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<script src="/srcipts/angular.js"></script>
<script src="/session6/script.js"></script>
</head>
<body ng-app="TEDU">
<div ng-controller="handleEventController">
<table>
<tr>
<td>Name</td>
<td>Likes</td>
<td>Dislikes</td>
<td>Minus</td>
<td>Actions</td>
</tr>
<tr ng-repeat="technology in technologies">
<td>{{technology.Name}}</td>
<td>{{technology.Likes}}</td>
<td>{{technology.Dislikes}}</td>
<td>{{technology.Minus}}</td>
<td>
<button ng-click="increaseLike(technology)">Like</button>
<button ng-click="increaseDislike(technology)">Dislike</button>
</td>
</tr>
</table>
</div>
</body>
</html>
Nguồn: TEDU
0 nhận xét:
Post a Comment