Share code or functions between pages


#1

I need some functions on almost every page like tap functions of my side navigation items. Is there a way to store them in one location instead of writing them in each page’s code behind file?


#2

Why don’t you just write the common function in a separate file and just import it all different files?


#3

Thats the goal. I couldn’t find a guide for it. How exactly do you do that?


#4

I’m not sure what is the challenge here, it’s as simple as,

common.ts

export function myCommonFunc() {
 ....
}

In controller

export * from "~/common";
...
...

In XML

<Page loaded="myCommonFunc" ...
...

#5

But I don’t want my common function to be executed on page load. The page load function does different things on different pages.


#6

That was just an example, you may use it for any purpose.