|
9 | 9 | import {NgForOfContext} from '@angular/common'; |
10 | 10 |
|
11 | 11 | import {AttributeMarker, defineComponent, templateRefExtractor} from '../../src/render3/index'; |
12 | | -import {bind, template, elementEnd, elementProperty, elementStart, getCurrentView, interpolation1, interpolation2, interpolation3, interpolationV, listener, load, nextContext, restoreView, text, textBinding} from '../../src/render3/instructions'; |
| 12 | +import {bind, template, elementEnd, elementProperty, elementStart, getCurrentView, interpolation1, interpolation2, interpolation3, interpolationV, listener, load, nextContext, restoreView, text, textBinding, elementContainerStart, elementContainerEnd} from '../../src/render3/instructions'; |
13 | 13 | import {RenderFlags} from '../../src/render3/interfaces/definition'; |
14 | 14 |
|
15 | 15 | import {NgForOf, NgIf, NgTemplateOutlet} from './common_with_def'; |
@@ -924,5 +924,50 @@ describe('@angular/common integration', () => { |
924 | 924 | expect(fixture.html).toEqual(''); |
925 | 925 | }); |
926 | 926 |
|
| 927 | + it('should allow usage on ng-container', () => { |
| 928 | + class MyApp { |
| 929 | + showing = false; |
| 930 | + static ngComponentDef = defineComponent({ |
| 931 | + type: MyApp, |
| 932 | + factory: () => new MyApp(), |
| 933 | + selectors: [['my-app']], |
| 934 | + consts: 3, |
| 935 | + vars: 1, |
| 936 | + /** |
| 937 | + * <ng-template #tpl>from tpl</ng-template> |
| 938 | + * <ng-container [ngTemplateOutlet]="showing ? tpl : null"></ng-container> |
| 939 | + */ |
| 940 | + template: (rf: RenderFlags, myApp: MyApp) => { |
| 941 | + if (rf & RenderFlags.Create) { |
| 942 | + template(0, (rf1: RenderFlags) => { |
| 943 | + if (rf1 & RenderFlags.Create) { |
| 944 | + text(0, 'from tpl'); |
| 945 | + } |
| 946 | + }, 1, 0, undefined, undefined, ['tpl', ''], templateRefExtractor); |
| 947 | + elementContainerStart(2, [AttributeMarker.SelectOnly, 'ngTemplateOutlet']); |
| 948 | + elementContainerEnd(); |
| 949 | + } |
| 950 | + if (rf & RenderFlags.Update) { |
| 951 | + const tplRef = load(1); |
| 952 | + elementProperty(2, 'ngTemplateOutlet', bind(myApp.showing ? tplRef : null)); |
| 953 | + } |
| 954 | + }, |
| 955 | + directives: () => [NgTemplateOutlet] |
| 956 | + }); |
| 957 | + } |
| 958 | + |
| 959 | + const fixture = new ComponentFixture(MyApp); |
| 960 | + expect(fixture.html).toEqual(''); |
| 961 | + |
| 962 | + fixture.component.showing = true; |
| 963 | + fixture.update(); |
| 964 | + expect(fixture.html).toEqual('from tpl'); |
| 965 | + |
| 966 | + fixture.component.showing = false; |
| 967 | + fixture.update(); |
| 968 | + expect(fixture.html).toEqual(''); |
| 969 | + |
| 970 | + }); |
| 971 | + |
927 | 972 | }); |
928 | 973 | }); |
0 commit comments