- <!DOCTYPE html>
- <html ng-app="myApp">
- <head>
- <link rel="stylesheet" href="style.css">
- <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
- <script src="index.js"></script>
- <script>
- var app = angular.module('myApp', []);
- app.config('Calculator', function($provide) {
- $provide.provider('Calculator', function() {
- this.$get = function() {
- var factory = {};
- factory.multiply = function(a, b) {
- return a * b;
- };
- return factory;
- };
- });
- });
- app.config('CalculatorProvider', function($provide)
- {
- $provide.provider('CalculatorProvider', function()
- {
- this.$get = function(Calculator)
- {
- var factory1 = {};
- square = function(a)
- {
- return Calculator.multiply(a,a);
- };
- cube = function(a)
- {
- return Calculator.multiply(a, Calculator.multiply(a,a));
- };
- return factory1;
- };
- });
- });
- app.controller('CalculatorController', function($scope, CalculatorProvider) {
- // $scope.answer = 0;
- $scope.Square = function() {
- $scope.answer = CalculatorProvider.square($scope.number);
- }
- $scope.Cube = function() {
- $scope.answer = CalculatorProvider.cube($scope.number);
- }
- });
- </script>
- </head>
- <body>
- <h1>square, cube using provider!</h1>
- <div ng-app="myApp">
- <div ng-controller="CalculatorController">
- Enter a number:
- <input type="number" ng-model="num" />
- <button ng-click="Square()">X<sup>2</sup></button>
- <button ng-click="Cube()">X<sup>3</sup></button>
- <div>{{answer}}</div>
- </div>
- </div>
- </body>
- </html>
[text] Code
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new:
File Description
- Code
- Paste Code
- 22 Oct-2020
- 1.79 Kb
You can Share it:
Latest Code Pastes