MCPcopy Index your code
hub / github.com/angular/angular / throwInvalidProviderError

Function throwInvalidProviderError

packages/core/src/render3/errors_di.ts:38–65  ·  view source on GitHub ↗
(
  ngModuleType?: Type<unknown>,
  providers?: any[],
  provider?: any,
)

Source from the content-addressed store, hash-verified

36}
37
38export function throwInvalidProviderError(
39 ngModuleType?: Type<unknown>,
40 providers?: any[],
41 provider?: any,
42): never {
43 if (ngModuleType && providers) {
44 const providerDetail = providers.map((v) => (v == provider ? '?' + provider + '?' : '...'));
45 throw new Error(
46 `Invalid provider for the NgModule '${stringify(
47 ngModuleType,
48 )}' - only instances of Provider and Type are allowed, got: [${providerDetail.join(', ')}]`,
49 );
50 } else if (isEnvironmentProviders(provider)) {
51 if (provider.ɵfromNgModule) {
52 throw new RuntimeError(
53 RuntimeErrorCode.PROVIDER_IN_WRONG_CONTEXT,
54 `Invalid providers from 'importProvidersFrom' present in a non-environment injector. 'importProvidersFrom' can't be used for component providers.`,
55 );
56 } else {
57 throw new RuntimeError(
58 RuntimeErrorCode.PROVIDER_IN_WRONG_CONTEXT,
59 `Invalid providers present in a non-environment injector. 'EnvironmentProviders' can't be used for component providers.`,
60 );
61 }
62 } else {
63 throw new Error('Invalid provider');
64 }
65}
66
67/** Throws an error when a token is not found in DI. */
68export function throwProviderNotFoundError(

Callers 2

validateProviderFunction · 0.90
providerToFactoryFunction · 0.90

Calls 4

stringifyFunction · 0.90
isEnvironmentProvidersFunction · 0.90
mapMethod · 0.80
joinMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…