IONIC-3 NavController抛出不能解决所有参数错误

时间:2018-09-02 12:42:46

标签: ionic-framework ionic3

我有一个无法解决的IONIC-3问题。我正在尝试实现由ionViewCanEnter触发的身份验证路由。但是,尽管我可以通过一个导航设置器,但不允许有多个。这是代码:

AuthService功能:

isAuthenticated(nav: NavController): boolean | Promise<any> {
const userAuth = this.uData.getAuthenticated;
const userProfile = this.uData.getUserProfile;

if (userAuth ) {
  //User is logged in, so let's check a few things.
  if (!userProfile.sign_up_complete) {
    //User has not completed sign up
    setTimeout(() => { nav.setRoot(CreateAccountPage) }, 0);
  }
  return true
} else {
  //User is not authenticated, return to walkthrough
  setTimeout(() => { nav.setRoot(WalkthroughPage) }, 0);
  return false
}}

调用示例:

ionViewCanEnter(): boolean | Promise<any> {
    return this.auth.isAuthenticated(this.nav);
}

如果我只有CreateAccountPage,则脚本可以正常运行。但是,当我添加WalkthroughPage时,它将引发以下错误:

Error: Can't resolve all parameters for ListingPage: (?, [object Object], [object Object], [object Object]).

这是与AuthService相关的错误。为清楚起见,WalkthroughPage代码如下:

import { Component, ViewChild } from '@angular/core';
import { IonicPage, NavController, Slides } from 'ionic-angular';
import { RemoteConfigProvider } from '../../providers/remote-config/remote-config';

import { LoginPage } from '../login/login';
import { SignupPage } from '../signup/signup';

@IonicPage()
@Component({
  selector: 'walkthrough-page',
  templateUrl: 'walkthrough.html'
})
export class WalkthroughPage {

  lastSlide = false;

  sign_up_enabled: null;
  sign_in_enabled: null;

  @ViewChild('slider') slider: Slides;

  constructor(public nav: NavController,
    public remoteConfig: RemoteConfigProvider) {
  }

  ionViewDidLoad() {
    this.remoteConfig.getValue('sign_up_enabled').then(t => {
      this.sign_up_enabled = t;
    })

    this.remoteConfig.getValue('sign_in_enabled').then(t => {
      this.sign_in_enabled = t;
    })
  }

  skipIntro() {
    this.lastSlide = true;
    this.slider.slideTo(this.slider.length());
  }

  onSlideChanged() {
    this.lastSlide = this.slider.isEnd();
  }

  goToLogin() {
    this.nav.push(LoginPage);
  }

  goToSignup() {
    this.nav.push(SignupPage);
  }
}

我试图比较两个页面,但没有确定确切原因。我欢迎任何想法。

1 个答案:

答案 0 :(得分:0)

对于那些遇到类似问题的人,解决方法很简单。我只是使用深层链接参考来解决所有问题。下面的示例。

isAuthenticated(nav: NavController): boolean | Promise<any> {
        const userAuth = this.userStore.getAuthenticated;
        const userProfile = this.userStore.getUserProfile;
        if (userAuth) {       
          return true
        } else {
          console.log('Auth guard: Not authenticated');
          setTimeout(() => { nav.setRoot('no-access') }, 0);
          return false
        }
      }