Skip to content

Commit 1232034

Browse files
dgp1130atscott
authored andcommitted
refactor(core): add ApplicationRef.prototype.bootstrapImpl with an injector parameter (angular#60622)
This is a roll forward of commit d5a8a1c. Nothing is meaningfully different, as we're trying again to see if the CI failure is reproducible. PR Close angular#60622
1 parent fcdef10 commit 1232034

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

packages/core/src/application/application_ref.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,14 @@ export class ApplicationRef {
498498
bootstrap<C>(
499499
componentOrFactory: ComponentFactory<C> | Type<C>,
500500
rootSelectorOrNode?: string | any,
501+
): ComponentRef<C> {
502+
return this.bootstrapImpl(componentOrFactory, rootSelectorOrNode);
503+
}
504+
505+
private bootstrapImpl<C>(
506+
componentOrFactory: ComponentFactory<C> | Type<C>,
507+
rootSelectorOrNode?: string | any,
508+
injector: Injector = Injector.NULL,
501509
): ComponentRef<C> {
502510
profiler(ProfilerEvent.BootstrapComponentStart);
503511

@@ -532,7 +540,7 @@ export class ApplicationRef {
532540
? undefined
533541
: this._injector.get(NgModuleRef);
534542
const selectorOrNode = rootSelectorOrNode || componentFactory.selector;
535-
const compRef = componentFactory.create(Injector.NULL, [], selectorOrNode, ngModule);
543+
const compRef = componentFactory.create(injector, [], selectorOrNode, ngModule);
536544
const nativeElement = compRef.location.nativeElement;
537545
const testability = compRef.injector.get(TESTABILITY, null);
538546
testability?.registerApplication(nativeElement);

packages/core/test/application_ref_spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,34 @@ describe('bootstrap', () => {
254254
),
255255
);
256256
});
257+
258+
describe('bootstrapImpl', () => {
259+
it('should use a provided injector', inject([ApplicationRef], (ref: ApplicationRef) => {
260+
class MyService {}
261+
const myService = new MyService();
262+
263+
@Component({
264+
selector: 'injecting-component',
265+
template: `<div>Hello, World!</div>`,
266+
})
267+
class InjectingComponent {
268+
constructor(readonly myService: MyService) {}
269+
}
270+
271+
const injector = Injector.create({
272+
providers: [{provide: MyService, useValue: myService}],
273+
});
274+
275+
createRootEl('injecting-component');
276+
const appRef = ref as unknown as {bootstrapImpl: ApplicationRef['bootstrapImpl']};
277+
const compRef = appRef.bootstrapImpl(
278+
InjectingComponent,
279+
/* rootSelectorOrNode */ undefined,
280+
injector,
281+
);
282+
expect(compRef.instance.myService).toBe(myService);
283+
}));
284+
});
257285
});
258286

259287
describe('destroy', () => {

0 commit comments

Comments
 (0)