<!-- index.htm
Author : Prof. Jake Rodriguez Pomperada, MAED-IT, MIT
Date : July 21, 2021 Wednesday 9:54 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>Palindrome 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(val_1) {
// find the length of a string
const len = val_1.length;
str_upper = val_1.toUpperCase();
// loop through half of the string
for (let i = 0; i < len / 2; i++) {
// check if first and last string are same
if (str_upper[i] !== str_upper[len - 1 - i]) {
return 'is not a Palindrome.';
}
}
return 'is a Palindrome.';
};
}).controller('Palindrome_Controller', function($scope, myService) {
$scope.check = function(val_1) {
$scope.myUserService = myService.myFunc(val_1);
}
});
</script>
<div ng-app="mainApp" ng-controller="Palindrome_Controller">
<form>
<table border="0" cellspacing=10>
<tr>Palindrome in AngularJS</tr>
<tr>
<td>Enter a String</td>
<td><input type="text" ng-model="val_1" ng-init="val_1=''" ng-keyup="check(val_1)"/></td>
</tr>
<table>
</form>
<b>The given {{val_1 | uppercase }} {{myUserService}}</b>
</div>
</body>
</html>
No comments:
Post a Comment