-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cant parse project when providing a service using a token and useFactory #21
Comments
Thanks for giving it a try! The problem is in the arrow function, you cannot use them in provider declaration because the context is not statically inferable. As I've mentioned in the readme, the project needs to be compatible with the AoT compilation of the framework. |
If thats the case, could you give me some direction in how I should write such code to make it work without arrow functions? I tried doing something like moving the function into an exported function in the same file, but I still got the error. |
You can use traditional function expression: {
provide: APP_INITIALIZER,
useFactory: function (configService: ConfigService) {
return function () {
configService.load();
}
},
deps: [ConfigService],
multi: true
} |
I see, ill give it a try, thanks :) |
I started working with ngrev today.
I think its a neat tool which is very important for the angular echo systems.
One issue that I found is that when I try to parse my project as is. I get an error about not allowing to use function. It always occured for all instance in my code where I tried to provide a token with useFactory, heres an example (I can't post the project that i'm working on specifically so ill only post examples):
{ provide: APP_INITIALIZER, useFactory: (configService: ConfigService) => () => configService.load(), deps: [ConfigService], multi: true },
so to overcome it, I just did something like this:
`
export function nothing(): any {}
...
{ provide:
APP_INITIALIZER,
useFactory: nothing,
deps: [ConfigService], multi: true
},`
which made the project parse, but ofc its not a great solution and also this configuration will not be visible in the ngrev output graph.
The text was updated successfully, but these errors were encountered: