I am in the process of developing a service for an Angular (2+) application, and I have noticed that all the documentation emphasizes using classes. However, my preference is to write the service as a function.
Here is the code that I want to use (even though it currently does not work):
import { Injectable } from '@angular/core';
export const AframeMessengerService = Injectable()(function AframeMessengerService() {
console.log('aframe messenger');
});
Unfortunately, when trying to implement this approach, I encounter the following error in the file where the service is being injected:
Cannot find name 'AframeMessengerService'.
On the other hand, here is the code that does work but does not align with my preferred method:
import { Injectable } from '@angular/core';
@Injectable()
export class AframeMessengerService {
constructor() {
console.log('aframe messenger');
}
}