angularjsangularjs-service

How to declare an AngularJs service with no parameters?


This works:

'use strict';

angular.module('MyApp').service('searchControllerPersistentData', ['$state', function ($state) 
{
    const Self = this;
}]);

but this gives an error in the controller where I try to inject the service:

'use strict';

angular.module('MyApp').service('searchControllerPersistentData', ['', function () 
{
    const Self = this;
}]);

The service will not need anything injected into it. How do I declare it?


Solution

  • Just remove the brackets :

    angular.module('MyApp').service('searchControllerPersistentData', function () 
    {
        const Self = this;
    });