irfanfadilah
irfanfadilah

Reputation: 43

NativeScript Public/Global Functions

Sample Codes:

exports.toggleSideDrawer = function() {
  frameModule.topmost().getViewById("sideDrawer").toggleDrawerState();
}

How can I use toggleSideDrawer without write it in every code-behind file?

For example, I have page A and B, in both of those pages, there's tap="toggleSideDrawer".

In short, make it available to all views/pages in the app.

Upvotes: 4

Views: 2930

Answers (1)

Nick Iliev
Nick Iliev

Reputation: 9670

You can use global in app.js

For example

in app.js

var application = require("application");

global.myGuide = 'John Smith';
global.backToMain = function() {
  global.require('ui/frame').topmost().navigate({
	moduleName: "main-page"
  });
};

application.start({ moduleName: "main-page" });

then in any of your code behind files you call the global variables/methods like this

var name = global.myGuide;
global.backToMain();
 

Upvotes: 3

Related Questions