【问题标题】:IONIC-3 NavController throwing can't resolve all parameters errorIONIC-3 NavController throwing can't resolve all parameters 错误
【发布时间】:2018-09-19 18:48:34
【问题描述】:

我对 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);
  }
}

我已尝试比较两个页面,但未确定确切原因。我欢迎任何想法。

【问题讨论】:

    标签: ionic-framework ionic3


    【解决方案1】:

    对于遇到类似问题的用户,解决方法很简单。我只是使用解决了所有问题的深度链接参考。下面的例子。

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

    【讨论】:

      猜你喜欢
      • 2017-09-29
      • 2018-11-27
      • 1970-01-01
      • 2018-09-22
      • 1970-01-01
      • 1970-01-01
      • 2021-12-04
      • 2020-04-07
      相关资源
      最近更新 更多