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

Function compileInjectable

packages/core/src/di/jit/injectable.ts:34–83  ·  view source on GitHub ↗
(type: Type<any>, meta?: Injectable)

Source from the content-addressed store, hash-verified

32 * injectable def (`ɵprov`) onto the injectable type.
33 */
34export function compileInjectable(type: Type<any>, meta?: Injectable): void {
35 let ngInjectableDef: any = null;
36 let ngFactoryDef: any = null;
37
38 // if NG_PROV_DEF is already defined on this class then don't overwrite it
39 if (!type.hasOwnProperty(NG_PROV_DEF)) {
40 Object.defineProperty(type, NG_PROV_DEF, {
41 get: () => {
42 if (ngInjectableDef === null) {
43 const compiler = getCompilerFacade({
44 usage: JitCompilerUsage.Decorator,
45 kind: 'injectable',
46 type,
47 });
48 ngInjectableDef = compiler.compileInjectable(
49 angularCoreDiEnv,
50 `ng:///${type.name}/ɵprov.js`,
51 getInjectableMetadata(type, meta),
52 );
53 }
54 return ngInjectableDef;
55 },
56 });
57 }
58
59 // if NG_FACTORY_DEF is already defined on this class then don't overwrite it
60 if (!type.hasOwnProperty(NG_FACTORY_DEF)) {
61 Object.defineProperty(type, NG_FACTORY_DEF, {
62 get: () => {
63 if (ngFactoryDef === null) {
64 const compiler = getCompilerFacade({
65 usage: JitCompilerUsage.Decorator,
66 kind: 'injectable',
67 type,
68 });
69 ngFactoryDef = compiler.compileFactory(angularCoreDiEnv, `ng:///${type.name}/ɵfac.js`, {
70 name: type.name,
71 type,
72 typeArgumentCount: 0, // In JIT mode types are not available nor used.
73 deps: reflectDependencies(type),
74 target: compiler.FactoryTarget.Injectable,
75 });
76 }
77 return ngFactoryDef;
78 },
79 // Leave this configurable so that the factories from directives or pipes can take precedence.
80 configurable: true,
81 });
82 }
83}
84
85type UseClassProvider = Injectable & ClassSansProvider & {deps?: any[]};
86

Callers 1

injectable.tsFile · 0.90

Calls 5

getCompilerFacadeFunction · 0.90
reflectDependenciesFunction · 0.90
getInjectableMetadataFunction · 0.85
compileInjectableMethod · 0.65
compileFactoryMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…