Calling one page method to another page


I have two pages one contacts and another one contacts history.

To avoid the reputation of code, i am calling contact method in contacts history page.

using declare var window and window.contacts=this; in contacts page.

and contact history page again declare var window. and calling the method

window.contacts.gethistory(id) when i first render in contacts page and go to contacts history page click the button that time contact method calling successfully. if i render the contacts history directly and click the button means the below error is coming

ERROR TypeError: Cannot read property ‘gethistory’ of undefined. How to solve this.

Thanks in Advance


This is definitely the Wrong Way. For Code that you use from different Pages, you should create a Service.

1 Like


Thanks for your reply.

instead of services we can create provider in ionic?

In service we can pages?

kindly reply.

A Service is a Provider, as far as i know :smiley:
You can use ionic generate service to generate a Service in Ionic.

Ok thanks for your reply.