Yes, a declarative user interface (i.e. xml) is actually a building system that parses xml and generates JS, so you don't need to.
So, if you want to do this manually, you will leave your component code yourself, and you will change your main screen code like this:
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="onLoad"> <StackLayout id='sl'> </StackLayout> </Page>
The first thing you will notice is that we loaded the page as a loaded event, you need to actually run your code somewhere in order to attach your component to the visual tree. The second thing we did was add an id to the StackLayout; this is technically not really required - you can navigate the NS tree and find the correct StackLayout; but for simplicity, adding an identifier is simplified.
Thus, the JS code on your page will look like this:
var builder = require('ui/builder'); var fs = require('file-system'); exports.onLoad = function(args) {
I believe that since you are adding a child to the loaded event, the page load event in the child component will be fired, but do not hold me for that. If this is not the case, you can manually start it at the same time when you add it ...
source share