feat(ivy): support injection even if no injector present (#23345)
- Remove default injection value from `inject` / `directiveInject` since it is not possible to set using annotations. - Module `Injector` is stored on `LView` instead of `LInjector` data structure because it can change only at `LView` level. (More efficient) - Add `ngInjectableDef` to `IterableDiffers` so that existing tests can pass as well as enable `IterableDiffers` to be injectable without `Injector` PR Close #23345
This commit is contained in:
@ -38,7 +38,6 @@ export class InjectableCompiler {
|
||||
private depsArray(deps: any[], ctx: OutputContext): o.Expression[] {
|
||||
return deps.map(dep => {
|
||||
let token = dep;
|
||||
let defaultValue = undefined;
|
||||
let args = [token];
|
||||
let flags: InjectFlags = InjectFlags.Default;
|
||||
if (Array.isArray(dep)) {
|
||||
@ -46,7 +45,7 @@ export class InjectableCompiler {
|
||||
const v = dep[i];
|
||||
if (v) {
|
||||
if (v.ngMetadataName === 'Optional') {
|
||||
defaultValue = null;
|
||||
flags |= InjectFlags.Optional;
|
||||
} else if (v.ngMetadataName === 'SkipSelf') {
|
||||
flags |= InjectFlags.SkipSelf;
|
||||
} else if (v.ngMetadataName === 'Self') {
|
||||
@ -69,8 +68,8 @@ export class InjectableCompiler {
|
||||
tokenExpr = ctx.importExpr(token);
|
||||
}
|
||||
|
||||
if (flags !== InjectFlags.Default || defaultValue !== undefined) {
|
||||
args = [tokenExpr, o.literal(defaultValue), o.literal(flags)];
|
||||
if (flags !== InjectFlags.Default) {
|
||||
args = [tokenExpr, o.literal(flags)];
|
||||
} else {
|
||||
args = [tokenExpr];
|
||||
}
|
||||
|
@ -948,7 +948,7 @@ export function createFactory(
|
||||
const flags = extractFlags(dependency);
|
||||
if (flags != InjectFlags.Default) {
|
||||
// Append flag information if other than default.
|
||||
directiveInjectArgs.push(o.literal(undefined), o.literal(flags));
|
||||
directiveInjectArgs.push(o.literal(flags));
|
||||
}
|
||||
args.push(o.importExpr(R3.directiveInject).callFn(directiveInjectArgs));
|
||||
}
|
||||
|
@ -53,11 +53,11 @@ describe('compiler compliance: dependency injection', () => {
|
||||
return new MyComponent(
|
||||
$r3$.ɵinjectAttribute('name'),
|
||||
$r3$.ɵdirectiveInject(MyService),
|
||||
$r3$.ɵdirectiveInject(MyService, (undefined as any), 1),
|
||||
$r3$.ɵdirectiveInject(MyService, (undefined as any), 2),
|
||||
$r3$.ɵdirectiveInject(MyService, (undefined as any), 4),
|
||||
$r3$.ɵdirectiveInject(MyService, (undefined as any), 8),
|
||||
$r3$.ɵdirectiveInject(MyService, (undefined as any), 10)
|
||||
$r3$.ɵdirectiveInject(MyService, 1),
|
||||
$r3$.ɵdirectiveInject(MyService, 2),
|
||||
$r3$.ɵdirectiveInject(MyService, 4),
|
||||
$r3$.ɵdirectiveInject(MyService, 8),
|
||||
$r3$.ɵdirectiveInject(MyService, 10)
|
||||
);
|
||||
}`;
|
||||
|
||||
|
Reference in New Issue
Block a user