Detect Execution Context within Typescript-Angular2-Nativescript code


Hi everyone,

I’m just starting with nativescript and angular2. I tried to play around a bit and I already have this question for you:

As I have mixed views in my code, the regular ng2-web and the ng2-nativescript ones, I’d like to bootstrap my app properly when the front kickstarts. My initial intuition is, from within main.ts, detect the execution environment, and according to it bootstrap and import the right app modules.

How can I know that the code is being executed from the tns run command line and not from ng serve or nodejs? Also, I need this detection to persist until the final android/ios app build of course.

Thanks for your insights!


I think it would be correct to separate the logic within two different main.ts, might even be better to separate the logic in two distinct projects, while abstracting the common logic.


You know, in fact I like the approach of the nativescript-ngx-magic npm module. What it does is insert a nativescript seed into your existing angular-cli project. Bit it’s smart, while it keeps apart nativescript folder structure from the angular src one (so yes there are two main.ts), it creates a shortcut within the nativescript folder to the angular /src/app folder so in fact, your views are accessible from anywhere.