feat: tree-shakeable providers API updates (#22655)
Rename @Injectable({scope -> providedIn}). Instead of {providedIn: APP_ROOT_SCOPE}, accept {providedIn: 'root'}. Also, {providedIn: null} implies the injectable should not be added to any scope. PR Close #22655
This commit is contained in:

committed by
Kara Erickson

parent
21e44c6ba9
commit
db56836425
@ -89,16 +89,24 @@ export class InjectableCompiler {
|
||||
}
|
||||
|
||||
injectableDef(injectable: CompileInjectableMetadata, ctx: OutputContext): o.Expression {
|
||||
let providedIn: o.Expression = o.NULL_EXPR;
|
||||
if (injectable.providedIn) {
|
||||
if (typeof injectable.providedIn === 'string') {
|
||||
providedIn = o.literal(injectable.providedIn);
|
||||
} else {
|
||||
providedIn = ctx.importExpr(injectable.providedIn);
|
||||
}
|
||||
}
|
||||
const def: MapLiteral = [
|
||||
mapEntry('factory', this.factoryFor(injectable, ctx)),
|
||||
mapEntry('token', ctx.importExpr(injectable.type.reference)),
|
||||
mapEntry('scope', ctx.importExpr(injectable.module !)),
|
||||
mapEntry('providedIn', providedIn),
|
||||
];
|
||||
return o.importExpr(Identifiers.defineInjectable).callFn([o.literalMap(def)]);
|
||||
}
|
||||
|
||||
compile(injectable: CompileInjectableMetadata, ctx: OutputContext): void {
|
||||
if (injectable.module) {
|
||||
if (injectable.providedIn) {
|
||||
const className = identifierName(injectable.type) !;
|
||||
const clazz = new o.ClassStmt(
|
||||
className, null,
|
||||
|
Reference in New Issue
Block a user