Sunday, March 13, 2016

Celsius To Fahrenheit Converter in AngularJS

A very simple program that I wrote using AngularJS that will ask the user to give the temperature in Celsius and then it will convert it into Fahrenheit 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>  Celsius To Fahrenheit 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> Celsius To Fahrenheit Converter in AngularJS</h3>
<div ng-app="myApp">
    <p>Enter temperature in Celsius :
        <input type="text" ng-model="fahrenheit" maxlength="5" size="3"/>
    </p><br>

    <p>The temperature in celsius is {{ fahrenheit }}&degC its equivalent to fahrenheit is {{ (fahrenheit * 9/5) + 32 | setDecimal:1}}&degF.</p>
</div>.
</body>
</html>




No comments:

Post a Comment