Skip to content

Commit 40f27a3

Browse files
crisbetoAndrewKushnir
authored andcommitted
Revert "feat(common): add injector input to ngTemplateOutlet (#44761)" (#44807)
This reverts commit ed21f5c. PR Close #44807
1 parent 94bfcdd commit 40f27a3

File tree

3 files changed

+7
-45
lines changed

3 files changed

+7
-45
lines changed

goldens/public-api/common/common.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,9 +581,8 @@ export class NgTemplateOutlet implements OnChanges {
581581
ngOnChanges(changes: SimpleChanges): void;
582582
ngTemplateOutlet: TemplateRef<any> | null;
583583
ngTemplateOutletContext: Object | null;
584-
ngTemplateOutletInjector: Injector | null;
585584
// (undocumented)
586-
static ɵdir: i0.ɵɵDirectiveDeclaration<NgTemplateOutlet, "[ngTemplateOutlet]", never, { "ngTemplateOutletContext": "ngTemplateOutletContext"; "ngTemplateOutlet": "ngTemplateOutlet"; "ngTemplateOutletInjector": "ngTemplateOutletInjector"; }, {}, never>;
585+
static ɵdir: i0.ɵɵDirectiveDeclaration<NgTemplateOutlet, "[ngTemplateOutlet]", never, { "ngTemplateOutletContext": "ngTemplateOutletContext"; "ngTemplateOutlet": "ngTemplateOutlet"; }, {}, never>;
587586
// (undocumented)
588587
static ɵfac: i0.ɵɵFactoryDeclaration<NgTemplateOutlet, never>;
589588
}

packages/common/src/directives/ng_template_outlet.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Directive, EmbeddedViewRef, Injector, Input, OnChanges, SimpleChanges, TemplateRef, ViewContainerRef} from '@angular/core';
9+
import {Directive, EmbeddedViewRef, Input, OnChanges, SimpleChange, SimpleChanges, TemplateRef, ViewContainerRef} from '@angular/core';
1010

1111
/**
1212
* @ngModule CommonModule
@@ -49,9 +49,6 @@ export class NgTemplateOutlet implements OnChanges {
4949
*/
5050
@Input() public ngTemplateOutlet: TemplateRef<any>|null = null;
5151

52-
/** Injector to be used within the embedded view. */
53-
@Input() public ngTemplateOutletInjector: Injector|null = null;
54-
5552
constructor(private _viewContainerRef: ViewContainerRef) {}
5653

5754
ngOnChanges(changes: SimpleChanges) {
@@ -62,17 +59,9 @@ export class NgTemplateOutlet implements OnChanges {
6259
viewContainerRef.remove(viewContainerRef.indexOf(this._viewRef));
6360
}
6461

65-
if (this.ngTemplateOutlet) {
66-
const {
67-
ngTemplateOutlet: template,
68-
ngTemplateOutletContext: context,
69-
ngTemplateOutletInjector: injector
70-
} = this;
71-
this._viewRef = viewContainerRef.createEmbeddedView(
72-
template, context, injector ? {injector} : undefined);
73-
} else {
74-
this._viewRef = null;
75-
}
62+
this._viewRef = this.ngTemplateOutlet ?
63+
viewContainerRef.createEmbeddedView(this.ngTemplateOutlet, this.ngTemplateOutletContext) :
64+
null;
7665
} else if (
7766
this._viewRef && changes['ngTemplateOutletContext'] && this.ngTemplateOutletContext) {
7867
this._viewRef.context = this.ngTemplateOutletContext;

packages/common/test/directives/ng_template_outlet_spec.ts

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {CommonModule} from '@angular/common';
10-
import {Component, ContentChildren, Directive, Inject, Injectable, InjectionToken, Injector, NO_ERRORS_SCHEMA, OnDestroy, QueryList, TemplateRef} from '@angular/core';
10+
import {Component, ContentChildren, Directive, Injectable, NO_ERRORS_SCHEMA, OnDestroy, QueryList, TemplateRef} from '@angular/core';
1111
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
1212
import {expect} from '@angular/platform-browser/testing/src/matchers';
1313

@@ -29,13 +29,7 @@ describe('NgTemplateOutlet', () => {
2929

3030
beforeEach(() => {
3131
TestBed.configureTestingModule({
32-
declarations: [
33-
TestComponent,
34-
CaptureTplRefs,
35-
DestroyableCmpt,
36-
MultiContextComponent,
37-
InjectValueComponent,
38-
],
32+
declarations: [TestComponent, CaptureTplRefs, DestroyableCmpt, MultiContextComponent],
3933
imports: [CommonModule],
4034
providers: [DestroyedSpyService]
4135
});
@@ -268,19 +262,8 @@ describe('NgTemplateOutlet', () => {
268262
expect(componentInstance.context1).toEqual({name: 'two'});
269263
expect(componentInstance.context2).toEqual({name: 'one'});
270264
});
271-
272-
it('should be able to specify an injector', waitForAsync(() => {
273-
const template = `<ng-template #tpl><inject-value></inject-value></ng-template>` +
274-
`<ng-container *ngTemplateOutlet="tpl; injector: injector"></ng-container>`;
275-
fixture = createTestComponent(template);
276-
fixture.componentInstance.injector =
277-
Injector.create({providers: [{provide: templateToken, useValue: 'world'}]});
278-
detectChangesAndExpectText('Hello world');
279-
}));
280265
});
281266

282-
const templateToken = new InjectionToken<string>('templateToken');
283-
284267
@Injectable()
285268
class DestroyedSpyService {
286269
destroyed = false;
@@ -307,15 +290,6 @@ class TestComponent {
307290
currentTplRef!: TemplateRef<any>;
308291
context: any = {foo: 'bar'};
309292
value = 'bar';
310-
injector: Injector|null = null;
311-
}
312-
313-
@Component({
314-
selector: 'inject-value',
315-
template: 'Hello {{tokenValue}}',
316-
})
317-
class InjectValueComponent {
318-
constructor(@Inject(templateToken) public tokenValue: string) {}
319293
}
320294

321295
@Component({

0 commit comments

Comments
 (0)