mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
committed by
Andrew Kushnir
parent
88003e27db
commit
945a3ad359
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user