I am looking for any constructor type of function in Angular. I have created a service but it is giving me an error. Please help to accomplish the task.
My error code:
var app = angular.module("app1", [])
.service('NumberService', function (a) {
    this.square = function () { return a * a; };
    this.cube = function () { return a * a * a; };
})
.controller('ServiceController', ['$scope', 'NumberService',
    function ($scope, NumberService) {
        $scope.getData = function () {
            //  alert('Button clicked' );
            var n = $scope.a;
            var ns = new NumberService(n);
            $scope.Square = ns.square();
            // alert($scope.Square);
            $scope.Cube = ns.cube();
        }
    }
]);
I want to create NumberService as Singleton class. In c++/java/c#:
class NumberService
{
    int a;
    public NumberService(int n){ a=n;}
    public int square(){ return a*a;}
    public in cube(){ return a*a*a;}
}
 
     
    