MCPcopy Create free account
hub / github.com/angular/angular / getUndecoratedInjectableFactory

Function getUndecoratedInjectableFactory

packages/core/src/di/r3_injector.ts:603–627  ·  view source on GitHub ↗
(token: Function)

Source from the content-addressed store, hash-verified

601}
602
603function getUndecoratedInjectableFactory(token: Function) {
604 // If the token has parameters then it has dependencies that we cannot resolve implicitly.
605 const paramLength = token.length;
606 if (paramLength > 0) {
607 throw new RuntimeError(
608 RuntimeErrorCode.INVALID_INJECTION_TOKEN,
609 ngDevMode &&
610 `Can't resolve all parameters for ${stringify(token)}: (${newArray(paramLength, '?').join(
611 ', ',
612 )}).`,
613 );
614 }
615
616 // The constructor function appears to have no parameters.
617 // This might be because it inherits from a super-class. In which case, use an injectable
618 // def from an ancestor if there is one.
619 // Otherwise this really is a simple class with no dependencies, so return a factory that
620 // just instantiates the zero-arg constructor.
621 const inheritedInjectableDef = getInheritedInjectableDef(token);
622 if (inheritedInjectableDef !== null) {
623 return () => inheritedInjectableDef.factory(token as Type<any>);
624 } else {
625 return () => new (token as Type<any>)();
626 }
627}
628
629function providerToRecord(provider: SingleProvider): Record<any> {
630 if (isValueProvider(provider)) {

Callers 1

Calls 5

stringifyFunction · 0.90
newArrayFunction · 0.90
joinMethod · 0.65
factoryMethod · 0.65

Tested by

no test coverage detected