<!DOCTYPE html>
<html ng-app="myModule">
<head>
<script src="Scripts/angular.min.js" type="text/javascript"></script>
</head>
<body style="font-family:Arial; font-size:medium; color:darkblue">
<div ng-controller="MyController">
<h2>Button click event in AnjularJS</h2>
<input type="button" value="Click Me!" ng-click="ButtonClickFunc()"/>
<br/>
<br/>
<div ng-bind="Message"></div>
</div>
<script type="text/javascript">
var app = angular.module('myModule', [])
app.controller('MyController', function ($scope)
{
$scope.ButtonClickFunc = function ()
{
$scope.Message = "Button clicked !!."
}
});
</script>
</body>
</html>
<!DOCTYPE html>
<html ng-app="myModule">
<head>
<script src="Scripts/angular.min.js" type="text/javascript"></script>
</head>
<body style="font-family:Arial; font-size:medium; color:darkblue">
<div ng-controller="myCtrl">
<h2>Mouse over event in AnjularJS</h2>
<h2>ng-mousemove="myFunction($event)"> Mouse Over Me!</h2>
<h2>Coordinates: x={{x}} , y= {{y}}</h2>
</div>
<script>
var app = angular.module('myModule', []);
app.controller('myCtrl', function ($scope)
{
$scope.myFunction = function (myEvent)
{
$scope.x = myEvent.clientX;
$scope.y = myEvent.clientY;
}
});
</script>
</body>
</html>
File Name: Script.js in Scripts folder.
/// <reference path="angular.min.js" />
var myApp = angular.module("myModule", []);
var myController = function ($scope)
{
$scope.Movies = [
{
MovieType: "Holywood Movies", likes: 0, dislikes: 0
},
{
MovieType: "Bolywood Movies", likes: 0, dislikes: 0
},
{
MovieType: "Tolywood Movies", likes: 0, dislikes: 0
},
{
MovieType: "German Movies", likes: 0, dislikes: 0
}
];
$scope.incrementLikes=function(Mov)
{ Mov.likes++ }
$scope.incrementDisLikes = function (Mov)
{ Mov.dislikes++ }
};
myApp.controller("myCont", myController);
<!DOCTYPE html>
<html ng-app="myModule">
<head>
<script src="Scripts/angular.min.js"type="text/javascript"></script>
<script src="Scripts/Script.js"></script>
<style>
table, th, td
{
border: 1px solid grey;
border-collapse: collapse;
padding: 5px;
}
table tr:nth-child(odd)
{
background-color: #ffe6e6;
}
table tr:nth-child(even)
{
background-color: #ccffcc;
}
</style>
</head>
<body style="font-family:Arial; font-size:medium; color:darkblue">
<div ng-controller="myCont">
<h2>Event Handling in AngularJS</h2>
<table border="0">
<tr>
<th>Movie Type</th>
<th>Likes</th>
<th>Dislikes</th>
<th></th>
<th></th>
</tr>
<tr ng-repeat="movie in Movies">
<td>{{movie.MovieType}}</td>
<td>{{movie.likes}}</td>
<td>{{movie.dislikes}}</td>
<td><input type="button" value="Like" ng-click="incrementLikes(movie)"/></td>
<td><input type="button" value="Dislike" ng-click="incrementDisLikes(movie)"/></td>
</tr>
</table>
</div>
</body>
</html>
<!DOCTYPE html>
<html ng-app>
<head>
<script src="Scripts/angular.min.js" type="text/javascript"></script>
</head>
<body style="font-family:Arial; font-size: medium; color:darkblue">
<div>
<input type="button" value="Click to count" ng-keypress ="count=count+1" ng-init ="count=0"/>
<br/><br/>
key press count=: {{count}}
</div>
</body>
</html>