【问题标题】:Runtime error can't resolve all parameters for UserService: (?)运行时错误无法解析 UserService 的所有参数:(?)
【发布时间】:2017-09-04 12:02:23
【问题描述】:

我是 ionic 新手,我不希望我的侧边栏有一个包含用户个人资料的标题,根据谁登录应用程序,他/她的详细信息会像其他类似应用程序一样显示。但是我在下面遇到了这个错误。

运行时错误无法解析 UserService 的所有参数:(?)。

下面是我的代码:

import { Injectable } from '@angular/core';
// import { Global } from '../../providers/global';

@Injectable()
export class UserService {
  constructor( public storage: Storage

       ) 
    {

  }

  user: any;
  token_type: any;
  access_token: any;
  refresh_token:any;

  getAccount(): any{
   return this.storage.get('user').then((value) => {
      return value;
    });

}

}

环境详情:

cli packages: (/usr/lib/node_modules)

    @ionic/cli-utils  : 1.9.2
    ionic (Ionic CLI) : 3.9.2

global packages:

    Cordova CLI : 7.0.1 

local packages:

    @ionic/app-scripts : 2.0.2
    Cordova Platforms  : none
    Ionic Framework    : ionic-angular 3.5.3

System:

    Node : v6.11.1
    npm  : 3.10.10 
    OS   : Linux 4.10

寻求帮助。提前致谢。

【问题讨论】:

  • 您是否在providers 数组中添加了UserService AppModule/Component
  • 是的,我添加了它。但还是不行。
  • 不是UserServiceStorage(这是UserService中的一个参数)是罪魁祸首。
  • 检查您是否将IonicStorageModule.forRoot() 添加到您的imports array

标签: node.js angular cordova ionic-framework ionic3


【解决方案1】:

正如 cmets 中所指出的,UserSerivce 本身不是问题。相反,它是存储,没有正确提供。确保您已在 AppModule 中导入了 Storage 模块,如下所示:

import { IonicStorageModule } from '@ionic/storage'; // <---- Add this!


@NgModule({
  declarations: [
    // ...
  ],
  imports: [      
    BrowserModule,
    IonicModule.forRoot(MyApp),
    IonicStorageModule.forRoot() // <--- Add this!
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    // ...
  ],
  providers: [
    // ...
  ]
})
export class AppModule {}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-25
    • 2017-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多