How to use xml-snippet as itemTemplate for dynamically created ListView



in our NativeScript we share code snippets between different pages, like the itemTemplate of a ListView:

<ListView items="{{ items}}">

where list-template.xml contains the snippet for an itemTemplate, e.g.

         <Label text="{{ name }}" />

My question is how to do the exact same thing for a dynamically created ListView from JavaScript code.
Right now, I assign the template like that:

myListView.itemTemplate =
         <Label text="{{ name }}" />

But assigning the template this way is not very flexible, as I am already sharing the template from the XML file.
In Angular, I could use the templateURL, to refer to the XML file (or HTML), but I use Vanilla JS. Is there anything similar I could do?

I am thankful for any advice.


At this moment; to my knowledge the only way to do this in PAN (Plain Awesome NativeScript) is to use my NativeScript-DynamicLoader plugin. It allows you to dynamically load in parts of the view screen.


Hi Nathanael,

thanks for your response. I’ll have a look at your plugin :wink: