无法解析Page:(?)的所有参数

时间:2019-08-22 09:36:38

标签: angular typescript ionic3

我正在构建一个离子项目,并希望使用Injectable类Requests来管理全局可用的变量和方法。 我试图将其注入到LoginPage中,但是它引发了以下错误:

  

未捕获的错误:无法解析LoginPage的所有参数:(?)。我有   从示例代码中删除了一些不会干扰的内容   问题。

奇怪的是:当我使用LoginPage时出现 only 问题  Requests类中的任何位置。即使从未使用过该代码。我已经在示例代码中对其进行了标记。 app.module.ts:

import { FormsModule } from '@angular/forms';
import { AuthService } from './../providers/auth-service/auth-service';
import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { IonicStorageModule } from '@ionic/storage';
import { HttpClientModule } from '@angular/common/http';
import { Requests } from '../providers/requests/requests';

import { MyApp } from './app.component';
import { LoginPage } from '../pages/login/login';

@NgModule({
  declarations: [
    MyApp,
    LoginPage,
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    IonicModule.forRoot(MyApp),
    IonicStorageModule.forRoot()
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    LoginPage,
  ],
  providers: [
    Requests,
  ]
})

export class AppModule {}

Requests.ts:

import { Injectable } from '@angular/core';;
import { LoginPage } from '../../pages/login/login'

@Injectable()
export class Requests {
  constructor() {

  }

  public whatever(ret: any){
    ret.navCtrl.setRoot(LoginPage);
    // Whenever i remove the line above, everything works fine.
    // This method isn't called at any time.
    // However, i need it to reference LoginPage here.
  }
}

LoginPage.ts:

import { Requests } from '../../providers/requests/requests';
import { Component } from '@angular/core';
import { NavController, NavParams, MenuController, AlertController, 
LoadingController, Loading, IonicPage } from 'ionic-angular';

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

  constructor(public request: Requests) {}
}

我试图在一个示例项目中复制它,但是不幸的是无法复制。您对要寻找的东西有什么建议吗?谢谢。

0 个答案:

没有答案