fix: consistently rewrite Injector to INJECTOR (#23008)
In Ivy mode we rewrite references to Injector to INJECTOR in ngInjectableDef, to fix tree-shaking. This changes the rewrite to happen always, even in non-Ivy mode, and makes Angular understand INJECTOR across the board at runtime. PR Close #23008
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Component, Injectable, NgModule} from '@angular/core';
|
||||
import {Component, INJECTOR, Injectable, NgModule} from '@angular/core';
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
import {renderModuleFactory} from '@angular/platform-server';
|
||||
import {BasicAppModuleNgFactory} from 'app_built/src/basic.ngfactory';
|
||||
@ -142,4 +142,28 @@ describe('ngInjectableDef Bazel Integration', () => {
|
||||
TestBed.configureTestingModule({});
|
||||
expect(TestBed.get(Service).value).toEqual(true);
|
||||
});
|
||||
|
||||
it('NgModule injector understands requests for INJECTABLE', () => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [{provide: 'foo', useValue: 'bar'}],
|
||||
});
|
||||
expect(TestBed.get(INJECTOR).get('foo')).toEqual('bar');
|
||||
});
|
||||
|
||||
it('Component injector understands requests for INJECTABLE', () => {
|
||||
@Component({
|
||||
selector: 'test-cmp',
|
||||
template: 'test',
|
||||
providers: [{provide: 'foo', useValue: 'bar'}],
|
||||
})
|
||||
class TestCmp {
|
||||
}
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [TestCmp],
|
||||
});
|
||||
|
||||
const fixture = TestBed.createComponent(TestCmp);
|
||||
expect(fixture.componentRef.injector.get(INJECTOR).get('foo')).toEqual('bar');
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user