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:
Misko Hevery
2018-04-12 15:54:16 -07:00
committed by Igor Minar
parent 6f213a74f2
commit da31db757b
21 changed files with 175 additions and 105 deletions

View File

@ -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];
}