@@ -147,15 +147,15 @@ export class ListViewComponent<T = any> implements DoCheck, OnDestroy, AfterCont
147
147
// The itemTemplateQuery may be changed after list items are added that contain <template> inside,
148
148
// so cache and use only the original template to avoid errors.
149
149
this . fallbackItemTemplate = this . itemTemplateQuery ;
150
- if ( this . _templateMap ) {
151
- // sometimes templates are registered before loader is ready, so we update here
152
- this . _templateMap . forEach ( ( t ) => ( t . location = this . loader ) ) ;
153
- } else if ( this . fallbackItemTemplate ) {
150
+ if ( this . fallbackItemTemplate && ! this . _templateMap ?. has ( 'default' ) ) {
154
151
// apparently you can create a Core ListView without a template...
152
+ // we also add a fallback default for when the user sets multiple templates but no templateSelector
155
153
this . registerTemplate ( 'default' , this . fallbackItemTemplate ) ;
156
154
}
157
155
158
156
if ( this . _templateMap ) {
157
+ // sometimes templates are registered before loader is ready, so we update here
158
+ this . _templateMap . forEach ( ( t ) => ( t . location = this . loader ) ) ;
159
159
if ( NativeScriptDebug . isLogEnabled ( ) ) {
160
160
NativeScriptDebug . listViewLog ( 'Setting templates' ) ;
161
161
}
@@ -219,6 +219,12 @@ export class ListViewComponent<T = any> implements DoCheck, OnDestroy, AfterCont
219
219
// this should never enter if it creates the view
220
220
const templateKey = typeof lview . itemTemplateSelector === 'function' ? lview . itemTemplateSelector ( currentItem , index , items ) : 'default' ;
221
221
template = this . _templateMap . get ( templateKey ) ;
222
+ if ( ! template ) {
223
+ if ( NativeScriptDebug . isLogEnabled ( ) ) {
224
+ NativeScriptDebug . listViewError ( `Template for key '${ templateKey } ' not found.` ) ;
225
+ }
226
+ return ;
227
+ }
222
228
args . view = template . create ( { index, data : currentItem } ) ;
223
229
}
224
230
this . setupViewRef ( template . getEmbeddedViewRef ( args . view ) , currentItem , index , args . view ) ;
0 commit comments