2017-05-14 68 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');