ngMocks.get
Returns a component, directive, service or token, which can be attribute or structural directives, which belongs to the current element.
ngMocks.get( debugElement, Component, notFoundValue? )
const component = ngMocks.get(fixture.debugElement, MyComponentType);
ngMocks.get( debugElement, Directive, notFoundValue? )
const directive = ngMocks.get(fixture.debugElement, MyDirectiveType);
ngMocks.get( Service )
const service = ngMocks.get(MyServiceType);
or simply with selectors which are supported by ngMocks.find
.
ngMocks.get( cssSelector, Directive, notFoundValue? )
const directive = ngMocks.get('app-component', MyDirectiveType);
ngMocks.get( cssSelector, Component, notFoundValue? )
const component = ngMocks.get('app-component', AppComponentType);
Root providers
If you need to get a root provider, then ngMocks.get
should be called without the first parameter:
const appId = ngMocks.get(APP_ID);