How to declare an AngularJs service with no parameters?

69 views Asked by At

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?

1

There are 1 answers

1
Bill P On BEST ANSWER

Just remove the brackets :

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