In this article I would like to discuss how to write a program that AngularJS to check if the given number is odd or even numbers.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website, kindly contact me also at my email address also. Thank you.

My email address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.

Program Listing

<!-- index.htm
  Author   : Prof. Jake Rodriguez Pomperada, MAED-IT, MIT
  Date     : July 21, 2021  Wednesday  1:33 PM
  Place    : Bacolod City, Negros Occidental
  Websites : www.jakerpomperada.com and www.jakerpomperada.blogspot.com
  Email    : jakerpomperada@gmail.com
 -->
<html ng-app="mainApp">
<head>
	<title>Odd and Even Numbers in AngularJS</title>
</head>
<style>
body {
	font-family: arial;
	font-size: 25px;
	font-weight: bold;
}
</style>
<script type="text/javascript" src="angular.min.js">
</script>

<script type="text/javascript">

// AngularJS Controller Declaration
angular.module('mainApp', []).service('myService', function() {
  this.myFunc = function(x) {

    if (Number(x) % 2 === 0)
      return 'EVEN';
    else
      return 'ODD';
  };
}).controller('Odd_Even_Controller', function($scope, myService) {
  $scope.check = function(num) {
    $scope.myUserService = myService.myFunc(num);
  }

});
</script>

<div ng-app="mainApp" ng-controller="Odd_Even_Controller">
	<form>
	<table border="0" cellspacing=10>
	<tr>Odd and Even Numbers in AngularJS</tr>
	<tr>
  	<td>Enter a Number </td>
	<td><input type="number" ng-model="val_1" ng-init="val_1=0" ng-keyup="check(val_1)"/></td>
	</tr>
	<table>
	</form>
	 <b>The number entered is {{val_1}} which is {{myUserService}} number(s). </b>
</div>
</body>
</html>

Leave a Reply

Your email address will not be published.