Sunday, March 13, 2016

Kilograms To Pounds Converter in AngularJS

A very simple program that I wrote using AngularJS that will ask the user to give the weight in kilograms and then it will convert it into pounds equivalent. The code is very simple and easy to understand for anyone interested in AngularJS programming.

If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.



Sample Program Output

Program Listing

<html>
<head> 
<title> Kilograms To Pounds Converter in AngularJS </title>
</head>
<script type="text/javascript" src="angular.js"></script>
<script>
var app = angular.module('myApp', []);

app.filter('singleDecimal', function ($filter) {
    return function (input) {
        if (isNaN(input)) return input;
        return Math.round(input * 10) / 10;
    };
});

app.filter('setDecimal', function ($filter) {
    return function (input, places) {
        if (isNaN(input)) return input;
         var factor = "1" + Array(+(places > 0 && places + 1)).join("0");
        return Math.round(input * factor) / factor;
    };
});

app.controller('Ctrl', function ($scope) {
    $scope.val = 1.56;
});
</script>
<style>
p {
   color:blue;
   font-family: "arial";
   font-style: bold;
   font-size: 18px;
  }
  
h3{
   color:red;
   font-family: "arial";
   font-style: bold;
   font-size: 20px;
  }
  
 input[type='text'] 
   { 
   color:blue;
   font-family: "arial";
   font-size: 18px;
   font-style: bold;
   }
 </style>
 <body bgcolor="yellow">
<br><br>
<h3>Kilograms To Pounds Converter in AngularJS</h3>
<div ng-app="myApp">
    <p>How many kilograms :
        <input type="text" ng-model="kilograms" maxlength="5" size="3"/>
    </p><br>
    <p>The weight in kilogram(s) is {{kilograms}} kg(s) its equivalent in pounds is {{ kilograms * 2.20462262 | setDecimal:0 }} lbs.</p>
</div>.
</body>
</html>
 



No comments:

Post a Comment