diff --git a/packages/core/src/view/ng_module.ts b/packages/core/src/view/ng_module.ts index 15496ce80f..bd660bf817 100644 --- a/packages/core/src/view/ng_module.ts +++ b/packages/core/src/view/ng_module.ts @@ -43,7 +43,7 @@ export function moduleDef(providers: NgModuleProviderDef[]): NgModuleDefinition let isRoot: boolean = false; for (let i = 0; i < providers.length; i++) { const provider = providers[i]; - if (provider.token === APP_ROOT) { + if (provider.token === APP_ROOT && provider.value === true) { isRoot = true; } if (provider.flags & NodeFlags.TypeNgModule) { diff --git a/packages/core/test/view/ng_module_spec.ts b/packages/core/test/view/ng_module_spec.ts index 3d569c844b..34ce8fbeb9 100644 --- a/packages/core/test/view/ng_module_spec.ts +++ b/packages/core/test/view/ng_module_spec.ts @@ -14,6 +14,7 @@ import {NgModuleDefinition, NgModuleProviderDef, NodeFlags} from '@angular/core/ import {moduleDef, moduleProvideDef, resolveNgModuleDep} from '@angular/core/src/view/ng_module'; import {createNgModuleRef} from '@angular/core/src/view/refs'; import {tokenKey} from '@angular/core/src/view/util'; +import {APP_ROOT} from '../../src/di/scope'; class Foo {} @@ -229,4 +230,29 @@ describe('NgModuleRef_ injector', () => { ref.destroy(); expect(Service.destroyed).toBe(1); }); + + describe('moduleDef', () => { + function createProvider(token: any, value: any) { + return { + index: 0, + flags: NodeFlags.TypeValueProvider | NodeFlags.LazyProvider, + deps: [], token, value + }; + } + + it('sets isRoot to `true` when APP_ROOT is `true`', () => { + const def = moduleDef([createProvider(APP_ROOT, true)]); + expect(def.isRoot).toBe(true); + }); + + it('sets isRoot to `false` when APP_ROOT is absent', () => { + const def = moduleDef([]); + expect(def.isRoot).toBe(false); + }); + + it('sets isRoot to `false` when APP_ROOT is `false`', () => { + const def = moduleDef([createProvider(APP_ROOT, false)]); + expect(def.isRoot).toBe(false); + }); + }); });