1

I am running this code, this is for square the number and it is generating some error on the console that i am not able to get it.

Error enter image description here

My Code goes here

<html>
    <head>
        <title>Angular JS Services</title>
        <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
    </head>
    <body>
        <h2>AngularJS Sample Application</h2>
        <div ng-app="mainApp" ng-controller="CalcController">
            <p>Enter a number: <input type="number" ng-model="number" />
            <button ng-click="square()">X<sup>2</sup></button>
            <p>Result: {{result}}</p>
        </div>


        <script>
        var mainapp = angular.module("mainApp", []);

        mainapp.factory('MathObjasService', function(a){
            var factorysrrvice = {};
            factorysrrvice.multiply = function(a, b){
                return a * b;
            }                 

            return factorysrrvice;
        });

        mainapp.service("CalSquareService", ["MathObjasService", function(MathObjasService){
            this.doubling = function(a){
                return MathObjasService.multiply(a, a);      
            }
        }]);

        mainapp.controller("CalcController", ["$scope", "CalSquareService", function($scope, CalSquareService){
            $scope.square = function(){
                $scope.result = CalSquareService.doubling($scope.number);
            }
        }]);

        </script>
    </body>
</html>

Could anyone help me on this where i went wrong Please?

4
  • 1
    Remove a from argument in mainapp.factory('MathObjasService', function(a){ ...}) Commented Sep 1, 2015 at 5:47
  • If you see the console actual error is Unknown provider: aProvider <- a <- MathObjasService <- CalSquareService Commented Sep 1, 2015 at 5:50
  • what is the expected value of a Commented Sep 1, 2015 at 5:52
  • jsfiddle.net/arunpjohny/aornfpw8/2 Commented Sep 1, 2015 at 5:57

1 Answer 1

1

There is no service named a which you inject in your factory

mainapp.factory('MathObjasService', function(a){
                                            ^^^ -> unknown provider

Just remove a from factory

try like this

mainapp.factory('MathObjasService', function(){});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.