Wisdom Materials
Home
About Us
Our Clients
Careers
Services
Education
Jobs
News
Business
Health
Astrology
Entertainment
RealEstate
Devotion
Contact Us
AngularJS
/ AngularJS Services
Program Name
Write a Program for AngularJS square Service.
Theory
AngularJS Services are functions used to do tasks.
Program Code
Copy Program Code
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"> </script> <h2>AngularJS - Square of a Number Application</h2> <div ng-app = "App99" ng-controller = "ControllerSquare"> <p>Enter a number: <input type = "number" ng-model = "number" /></p> <button ng-click = "square()">Square of a Number</button> <p>Result: {{result}}</p> </div> <script> var App99 = angular.module("App99", []); App99.factory('SquareService', function () { var factory = {}; factory.multiply = function (a, b) { return a * b } return factory; }); App99.service('CalcService', function (SquareService) { this.square = function (a) { return SquareService.multiply(a, a); } }); App99.controller('ControllerSquare', function ($scope, CalcService) { $scope.square = function () { $scope.result = CalcService.square($scope.number); } }); </script>
Input
Enter a number = number variable
Output
Home
Back
Home
About Us
Our Clients
Careers
Services
Education
Jobs
News
Business
Health
Astrology
Entertainment
RealEstate
Devotion
Contact Us