Get Access To Angular Service Instance From Javascript Code
What I'm trying to do is have some testing assertions based on the data in the Angular service, i.e. we're trying to create E2E tests and the tool we're using allows us to execute
This works for me in Angular 7 using ng.probe()
:
window.ng.probe(window.getAllAngularRootElements()[0])
.injector.view.root.ngModule._providers
.find(p => p && p.constructor && p.constructor.name === 'MyServiceName');
And I guess it is not possible to do it another way without ng.probe()
Post a Comment for "Get Access To Angular Service Instance From Javascript Code"