ngrx EffectsModule 使 Http 服务未定义 [英] ngrx EffectsModule makes Http service undefined

查看:28
本文介绍了ngrx EffectsModule 使 Http 服务未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 @ngrx/effects v4.0.5 和 Angular v4.4.4.

Using @ngrx/effects v4.0.5 with Angular v4.4.4.

当我在 app.module.ts 中导入 EffectsModule 时,Http 服务变得未定义.

When I import EffectsModule in app.module.ts, the Http service becomes undefined.

一些代码:

// app.module.ts
import { BrowserModule, Title } from '@angular/platform-browser';
...
import { HttpModule, Http } from '@angular/http';
...
import { EffectsModule } from '@ngrx/effects';
import { AuthenticationModule } from './authentication/authentication.module';
import { MyEffects } from './myEffects.ts'
...

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    HttpModule,
    ...
    AuthenticationModule,
    StoreModule.forRoot(reducers),
    EffectsModule.forRoot([MyEffects])
  ]
  ...
})
export class AppModule { }

请注意,MyEffects 与身份验证功能没有任何关系.

Please note that MyEffects isn't related in any way to the authentication feature.

当我在我的应用程序中使用我可以使用的第一个东西时,登录按钮,我调用 AuthenticationService.signIn,它反过来调用它的 http 实例 this.http.post(...

When I use the first thing I can use in my app, the sign in button, I call AuthenticationService.signIn, which in turn calls its http instance this.http.post(...

并且 this.http 未定义(收到一条错误消息,通过调试器查看它,发现它未定义 - this 不是未定义的并且有一个 http 未定义的属性)

And this.http is undefined (got an error message, looked into it via debugger, and found it undefined - this is not undefined and has a http property which is undefined)

如果我注释掉 EffectsModule.forRoot([MyEffects]),http 服务重新出现"并且登录有效.

If I comment out EffectsModule.forRoot([MyEffects]), the http service "reappears" and the sign in works.

请注意,MyEffects 与身份验证功能没有任何关系.

Please note that MyEffects isn't related in any way to the authentication feature.

推荐答案

@angular/ 包从 4.4.4 升级到 4.4.5解决了问题O_O'

Upgrading the @angular/ packages from 4.4.4 to 4.4.5 solved the problem O_O'

这篇关于ngrx EffectsModule 使 Http 服务未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆