Tuesday, 8 December 2020

AngularJS-Using service method .WAP to Calculate Circle and Circumference

 

<html>

<script src="angular.min.js"></script>

 

<body>

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

AreaofCircle={{AreaofCircle}}<br>

Circumference={{Circumference}}

</div>

</body>

 

<script>

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

app1.service('circle', function() {

 

var pi= 3.14;

this.Area=function(r)

{

//var pi=3.14;

return pi*r*r;

}

 

this.Circumference=function(r)

{

return pi*r*2;

}

});

 app1.controller('myCtrl', function($scope,circle) {

$scope.AreaofCircle=circle.Area(5);

$scope.Circumference=circle.Circumference(5);

});

</script>

 

</html>