1

I'd like to call the method refreshMe () from the home.ts. But I get the message that it is not in the typeof.

Here is what i've tried:

=> settings.ts

import { HomePage } from '../home/home'

[...]

HomePage.refreshMe();


=> home.ts

refreshMe() {
      this.navCtrl.setRoot(this.navCtrl.getActive().component);
    }


Here again the exact error message:

Property 'refreshMe' does not exist on type 'typeof HomePage'.

7
  • it may not be really DRY, but if the method is just one line, you should add that as a method in the component where you wan to call it. Injecting a page in another page may cause some issues later... Commented Jul 4, 2017 at 7:24
  • I see, how can i do this ? Im new to Ionic, can you maybe give me some example code ? Commented Jul 4, 2017 at 7:31
  • Possible duplicate of How to reload a Page from another class with Ionic3 Commented Jul 4, 2017 at 9:01
  • If it's ok for you, could you please delete this question since it's a duplicate of this one? Or is it somehow different? Thanks :) Commented Jul 4, 2017 at 9:02
  • Sry i'm not allowed to delete this. But yeah i guess its pretty the same. Commented Jul 4, 2017 at 9:06

1 Answer 1

3

UPDATED

Try something like this,

create a provider with ionic cli using the command,

ionic g provider providerName

now put your refreshMe() function inside the provider so that you can import the provider and use the refreshMe function wherever you want like this

import { NewProvider } from '../home/home'

constructor(public myProvider: NewProvider ){
   myProvider.refreshMe();
}
Sign up to request clarification or add additional context in comments.

8 Comments

I guess it worked. But now i cant load the Settingspage. The ony thing i get was this useless error: '[INFO:CONSOLE(1436)] "ERROR", source: file:///android_asset/www/build/main.js (1436)'
terminate it and run it again with ionic serve
Uncaught (in promise): Error: No provider for HomePage! injectionError@localhost:8100/build/main.js:1583:86 noProviderError@localhost:8100/build/main.js:1621:12 ReflectiveInjector_.prototype._throwOrNull@localhost:8100/build/main.js:3122:19 ReflectiveInjector_.prototype._getByKeyDefault@localhost:8100/build/main.js:3161:20 ReflectiveInjector_.prototype._getByKey@localhost:8100/build/main.js:3093:20 ReflectiveInjector_.prototype.get@localhost:8100/build/main.js:2962:16
in your app.module.ts add "HomePage" under "providers:"
Here are my providers: providers: [ StatusBar, SplashScreen, HomePage, File, {provide: ErrorHandler, useClass: IonicErrorHandler} ] .. I still got the Error: Uncaught (in promise): Error: No provider for NavController! injectionError@localhost:8100/build/main.js:1583:86 noProviderError@localhost:8100/build/main.js:1621:12 ReflectiveInjector_.prototype._throwOrNull@localhost:8100/build/main.js:3122:19 ReflectiveInjector_.prototype._getByKeyDefault@localhost:8100/build/main.js:3161:20
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.