How do I list all the dependency injectors of a component in angular?
This requirement is for unit testing.
I have an instance of a component created as follows :
component = fixture.componentInstance();
So in my test case, I need something like
console.log(component.constructor.params) // should print all the constructor parameteres
For ex in the below code :
constructor(private _logger: LoggerService, private _router: Router,
private _adminService: AdminService) {
}
I need to fetch array of DI's
0 -> LoggerService
1 -> Router
2 -> AdminService
You should be able to take advantage of Javascript's built in
argumentsobject.So if you just need the names of the classes of each dependency, you can put this in your constructor:
Logging the
dependenciesobject to the console should output:If your array needs to contain the full object instead of the name of the class, just remove the
.map()function from the constructor code.