@@ -70,6 +70,12 @@ describe('NgTemplateOutlet', () => {
70
70
detectChangesAndExpectText ( '' ) ;
71
71
} ) ) ;
72
72
73
+ it ( 'should do nothing if templateRef is `undefined`' , waitForAsync ( ( ) => {
74
+ const template = `<ng-container [ngTemplateOutlet]="undefined"></ng-container>` ;
75
+ fixture = createTestComponent ( template ) ;
76
+ detectChangesAndExpectText ( '' ) ;
77
+ } ) ) ;
78
+
73
79
it ( 'should insert content specified by TemplateRef' , waitForAsync ( ( ) => {
74
80
const template =
75
81
`<ng-template #tpl>foo</ng-template>` +
@@ -93,6 +99,21 @@ describe('NgTemplateOutlet', () => {
93
99
detectChangesAndExpectText ( '' ) ;
94
100
} ) ) ;
95
101
102
+ it ( 'should clear content if TemplateRef becomes `undefined`' , waitForAsync ( ( ) => {
103
+ const template =
104
+ `<tpl-refs #refs="tplRefs"><ng-template>foo</ng-template></tpl-refs>` +
105
+ `<ng-container [ngTemplateOutlet]="currentTplRef"></ng-container>` ;
106
+ fixture = createTestComponent ( template ) ;
107
+ fixture . detectChanges ( ) ;
108
+ const refs = fixture . debugElement . children [ 0 ] . references ! [ 'refs' ] ;
109
+
110
+ setTplRef ( refs . tplRefs . first ) ;
111
+ detectChangesAndExpectText ( 'foo' ) ;
112
+
113
+ setTplRef ( undefined ) ;
114
+ detectChangesAndExpectText ( '' ) ;
115
+ } ) ) ;
116
+
96
117
it ( 'should swap content if TemplateRef changes' , waitForAsync ( ( ) => {
97
118
const template =
98
119
`<tpl-refs #refs="tplRefs"><ng-template>foo</ng-template><ng-template>bar</ng-template></tpl-refs>` +
@@ -117,6 +138,14 @@ describe('NgTemplateOutlet', () => {
117
138
detectChangesAndExpectText ( 'foo' ) ;
118
139
} ) ) ;
119
140
141
+ it ( 'should display template if context is `undefined`' , waitForAsync ( ( ) => {
142
+ const template =
143
+ `<ng-template #tpl>foo</ng-template>` +
144
+ `<ng-container *ngTemplateOutlet="tpl; context: undefined"></ng-container>` ;
145
+ fixture = createTestComponent ( template ) ;
146
+ detectChangesAndExpectText ( 'foo' ) ;
147
+ } ) ) ;
148
+
120
149
it ( 'should reflect initial context and changes' , waitForAsync ( ( ) => {
121
150
const template =
122
151
`<ng-template let-foo="foo" #tpl>{{foo}}</ng-template>` +
0 commit comments