fix(core): Fix runInContext for NgModuleRef injector (#46877)

The `runInContext` for `NgModuleRef` was previously an infinite loop.

PR Close #46877
This commit is contained in:
Andrew Scott
2022-07-18 17:45:50 -07:00
committed by Andrew Kushnir
parent 88003e27db
commit 945a3ad359
2 changed files with 7 additions and 1 deletions
+1 -1
View File
@@ -98,7 +98,7 @@ export class NgModuleRef<T> extends viewEngine_NgModuleRef<T> implements Interna
}
runInContext<ReturnT>(fn: () => ReturnT): ReturnT {
return this.injector.runInContext(fn);
return this._r3Injector.runInContext(fn);
}
override destroy(): void {
@@ -141,6 +141,12 @@ describe('environment injector', () => {
expect(returnValue).toBe(3);
});
it('works with an NgModuleRef injector', () => {
const ref = TestBed.inject(NgModuleRef);
const returnValue = ref.injector.runInContext(() => 3);
expect(returnValue).toBe(3);
});
it('should make inject() available', () => {
const TOKEN = new InjectionToken<string>('TOKEN');
const injector = createEnvironmentInjector(