Ionic Uncaught(承诺):链接无效 [英] Ionic Uncaught (in promise): invalid link

查看:125
本文介绍了Ionic Uncaught(承诺):链接无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Ionic中遇到了 this.nav.push 的问题。我已经完成了登录/注册页面,但是当我登录时,我收到此错误消息。我必须从login.ts添加代码,例如home.ts(这是主页)?

i have propably problem with this.nav.push in Ionic. I have done a login/registration page but when i login i get this error message. I have to add code from login.ts and e.g home.ts(which is main page) ?


运行时错误

未捕获(承诺):无效链接:主页

Runtime 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 )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 )Object.onInvoke上的
http:// localhost:8100 / build / main .js:4622:37 )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 )n.runTask的
http:// localhost:8100 / build / polyfills.js:3:7153

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:当我想登录我的应用程序时出现问题。这是代码响应者
登录。

@edit: The problem occurs when I want login to my app. It's code respondent to login.

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 (这是执行我的腰部的公共功能,我有通行证和电子邮件,我需要输入登录)


auth-service.ts ( here is public function which execute my loin and where i have pass and email which I need to type in login )

  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', 'saimon@devdactic.com');
        observer.next(access);
        observer.complete();
      });
    }
  }

我不知道为什么这段代码错了。我的主页我的应用程序是home.ts,类是HomePage

I don't know why this code is wrong. My home page iny my app is home.ts and class is HomePage

推荐答案

你需要做的是添加@IonicPage( )在'@Component'之前导入'IonicPage',如下所示:
import {NavController,IonicPage}来自'ionic-angular';

what you need to do is to add @IonicPage() before '@Component' and import 'IonicPage' like this : import {NavController, IonicPage} from 'ionic-angular';

然后你需要为主页创建一个模块,即在主目录中,创建带有以下内容的home.module.ts

then you need to create a module for the homepage i.e in the home directory , create home.module.ts with the following contents

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 {}

并重新加载项目

这篇关于Ionic Uncaught(承诺):链接无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆