2017-05-14 101 views
2

我在Ionic中與this.nav.push存在問題。我已經完成了登錄/註冊頁面,但是當我登錄時,我收到了此錯誤消息。我必須從login.ts添加代碼,例如home.ts(這是主頁)?Ionic未捕獲(承諾):無效鏈接

Runtime Error
Uncaught (in promise): invalid link: HomePage


Error: Uncaught (in promise): invalid link: HomePage at d (http://localhost:8100/build/polyfills.js:3:3991) at l (http://localhost:8100/build/polyfills.js:3:3244) at Object.reject (http://localhost:8100/build/polyfills.js:3:2600) at NavControllerBase._fireError (http://localhost:8100/build/main.js:45465:16) at NavControllerBase._failed (http://localhost:8100/build/main.js:45453:14) at http://localhost:8100/build/main.js:45508:59 at t.invoke (http://localhost:8100/build/polyfills.js:3:11562) at Object.onInvoke (http://localhost:8100/build/main.js:4622:37) at t.invoke (http://localhost:8100/build/polyfills.js:3:11502) at n.run (http://localhost:8100/build/polyfills.js:3:6468) at http://localhost:8100/build/polyfills.js:3:3767 at t.invokeTask (http://localhost:8100/build/polyfills.js:3:12256) at Object.onInvokeTask (http://localhost:8100/build/main.js:4613:37) at t.invokeTask (http://localhost:8100/build/polyfills.js:3:12177) at n.runTask (http://localhost:8100/build/polyfills.js:3:7153)

@edit:當我想登錄到我的應用程序出現問題。它是代碼響應者 登錄。

login.ts

public login() { 
    this.showLoading() 
    this.auth.login(this.registerCredentials).subscribe(allowed => { 
     if (allowed) {   
     this.nav.push('HomePage'); 
     } else { 
     this.showError("Access Denied"); 
     } 
    }, 
     error => { 
     this.showError(error); 
     }); 
    } 

AUTH-service.ts(這裏是執行我的腰部,並在那裏我有通行證和電子郵件,我需要輸入登錄公共功能)

public login(credentials) { 
    if (credentials.email === null || credentials.password === null) { 
     return Observable.throw("Please insert credentials"); 
    } else { 
     return Observable.create(observer => { 
     // At this point make a request to your backend to make a real check! 
     let access = (credentials.password === "pass" && credentials.email === "email"); 
     this.currentUser = new User('Simon', '[email protected]'); 
     observer.next(access); 
     observer.complete(); 
     }); 
    } 
    } 

我不知道爲什麼這段代碼是錯誤的。我的主頁INY我的應用程序是home.ts和類是首頁

+0

歡迎來到StackOverflow!爲了讓我們更好地爲您提供幫助,請更新您的問題,以便以[**最小,完整和可驗證的示例**](http://stackoverflow.com/help/mcve)顯示所有相關代碼。如果您能讓我們知道您迄今爲止已經嘗試解決您的問題,也會有所幫助。有關詳細信息,請參閱有關[**如何提出良好問題**](http://stackoverflow.com/help/how-to-ask)的幫助文章,並參加該網站的[**遊覽**](http://stackoverflow.com/tour):) –

回答

5

你需要做的是「@Component」進口「IonicPage」像這樣前添加@IonicPage(): import {NavController, IonicPage} from 'ionic-angular';

然後您需要創建即主目錄的主頁的模塊,具有以下內容

import { NgModule } from '@angular/core'; 
import { IonicPageModule } from 'ionic-angular'; 
import { HomePage } from './home'; 

@NgModule({ 
    declarations: [ 
    HomePage 
    ], 
    imports: [ 
    IonicPageModule.forChild(HomePage), 
    ], 
    exports: [ 
    HomePage 
    ] 
}) 
export class HomePageModule {} 

創建home.module.ts並重新加載項目

+0

這對我來說,tnx! –

3

在你的代碼唯一的問題是,當你寫 this.nav.push('HomePage');在調用任何頁面時刪除''引號,並且像這樣寫。

this.nav.push(HomePage);沒有引號。

Above answer is for ionic2, in ionic3 there is lazy loading where you call like this this.nav.push('HomePage');