Friday, 4 November 2016

Decimal to Binary Conversion Using AngularJS


<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">

<h3> Decimal to Binary Conversion </h3>
<p>Enter a number: <input type = "number" ng-model = "number" /></p>
<button ng-click = "square()">Convert</sup></button>
<p>Result: {{result}}</p>

</div>

<script>

var app = angular.module('myApp', []);

app.service('hexafy', function()
{
    this.square = function (x)
 {
        return x.toString(2);
    }
});
app.controller('myCtrl', function($scope, hexafy)
{
 $scope.square = function() {
$scope.result = hexafy.square($scope.number);
}
});
</script>

</body>
</html>


Output :



No comments:

Post a Comment