2017-07-04 33 views
0

我想從home.ts中調用refreshMe()方法。但是我得到的信息是它不屬於這種類型。如何從TypeScript中的另一個類調用函數

這裏是我已經試過:

=> settings.ts

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

[...]

HomePage.refreshMe(); 


=> home.ts

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


這裏再次確切的錯誤信息:

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

+0

它可能不是真幹,但如果方法只是一條線,你應該補充的是,由於方法你想要調用它的組件。在另一個頁面中注入頁面可能會導致一些問題... – sebaferreras

+0

我明白了,我該如何做到這一點? Im新到Ionic,你能給我一些示例代碼嗎? – MrFlyingToasterman

+0

[如何用Ionic3從另一個類重新加載一個頁面]可能的重複(https://stackoverflow.com/questions/44901083/how-to-reload-a-page-from-another-class-with-ionic3) – sebaferreras

回答

1

修訂

嘗試這樣的事情,

創建使用下面的命令離子CLI提供商,

ionic g provider providerName 

現在把你的refreshMe()函數insi德提供商,讓你可以導入供應商,無論你想喜歡使用refreshMe功能這

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

constructor(public myProvider: NewProvider){ 
    myProvider.refreshMe(); 
} 
+0

我想它工作。但現在我不能加載設置頁面。我得到的ony事情是這個無用的錯誤:'[INFO:CONSOLE(1436)]「ERROR」,source:file:///android_asset/www/build/main.js(1436)' – MrFlyingToasterman

+0

終止它並再次運行它帶有離子服務 – Gowtham

+0

未捕獲(承諾):錯誤:沒有HomePage的提供者! injectionError @ http:// localhost:8100/build/main.js:1583:86 noProviderError @ http:// localhost:8100/build/main.js:1621:12 [email protected]:/ /localhost:8100/build/main.js:3122:19 [email protected]:// localhost:8100/build/main.js:3161:20 [email protected]:// localhost :8100/build/main.js:3093:20 [email protected]:// localhost:8100/build/main.js:2962:16 – MrFlyingToasterman

相關問題