我在Ionic中有 this.nav.push
的问题 . 我已经完成了登录/注册页面,但是当我登录时,我收到此错误消息 . 我必须从login.ts添加代码,例如home.ts(这是主页)?
运行时错误未捕获(在承诺中):无效链接:HomePage
错误:未捕获(在承诺中):无效链接:主页d(http:// localhost:8100 / build / polyfills.js:3:3991)at l(http:// localhost:8100 / build / polyfills.js :3:3244)在Object.reject(http:// localhost:8100 / build / polyfills.js:3:2600)处于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:/ /lhosthost:8100/build/polyfills.js:3:11562)在t.invoke的对象.onInvoke(http:// localhost:8100 / build / main.js:4622:37)(http:// localhost:8100) /build/polyfills.js:3:11502)在n.run(http:// localhost:8100 / build / polyfills.js:3:6468)的http:// localhost:8100 / build / polyfills.js:3 :377. at t.invokeTask(http:// localhost:8100 / build / polyfills.js:3:12256)at 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) )
@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', 'saimon@devdactic.com');
observer.next(access);
observer.complete();
});
}
}
我不知道为什么这段代码错了 . 我的主页我的应用程序是home.ts和类是HomePage
3 回答
你需要做的是在'@Component'之前添加@IonicPage()并像这样导入'IonicPage':
import {NavController, IonicPage} from 'ionic-angular';
然后你需要为主页创建一个模块,即在主目录中,使用以下内容创建home.module.ts
并重新加载项目
您的代码中唯一的问题是当您在调用任何页面时写入
this.nav.push('HomePage');
删除 ' ' 引号,并且这样写 .this.nav.push(HomePage);
没有引号 .我复制了登录示例 . 错误类似 .
主页的检查点:(1)检查home.module.ts是否(2)在home.ts中的'@Component'之前检查@IonicPage()(2)从app.module.ts中的declaration / entryComponents中删除HomePage开放式错误