@Injectable({
providedIn: 'root',
*/ useFactory: () => new MyService(MyAnotherService.myInteger) */
})
export class MyService{
constructor(private someInteger?: number) {
// doThings with someInteger
}
--aot build will complain that Warning: Can't resolve all parameters for...
In fact, due to the useFactory: () part, we are still able to run our application correctly. But I do not know if this is the right way or not
We can, of course, change the constructor to
constructor(private anotherService?: MyAnotherService) {
// doThings with anotherService
}
To shut the build warning, However I do not think that MyService should be dependent on MyAnotherService when It can be just dependent on a primitive, It's also bad for code reusability
What is the best thing to do in this situation?
from Correct use of Angular TypeScript constructor - Can't resolve all parameters for
No comments:
Post a Comment