类型“ AppModule”上不存在属性“ ngRedux”。

时间:2018-07-05 05:44:03

标签: angular redux react-redux angular6

我一直在努力在angular6中实现redux,它几乎完成了该应用程序运行正常,但是在节点cli中抛出了错误类型'AppModule'中不存在属性'ngRedux'。 strong>

  

当我在App.module.ts的导入和导出中添加NgRedux时,它会引发错误和应用程序   停止工作。

有什么解决方法吗?

  

我的app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { NgRedux, NgReduxModule } from '@angular-redux/store';
import { AppComponent } from './app.component';
import { MatButtonModule } from '@angular/material/button';
import { HomeComponent } from './home/home.component';
import { ProfileComponent } from './profile/profile.component';
import { MatInputModule } from '@angular/material/input';
import { MatCardModule } from '@angular/material/card';
import { MatBadgeModule } from '@angular/material/badge';

import { createLogger } from 'redux-logger';

import { IAppState, rootReducer, INITIAL_STATE } from './reducers/rootReducers';


@NgModule({
  declarations: [
    AppComponent,
    HomeComponent,
    ProfileComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    NgReduxModule,
    MatButtonModule,
    MatInputModule,
    MatCardModule,
    MatBadgeModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { 

      constructor(ngRedux: NgRedux<IAppState>) {
      // ngRedux.configureStore(rootReducer, INITIAL_STATE);
      this.ngRedux = ngRedux;
      ngRedux.configureStore(rootReducer, INITIAL_STATE, [ createLogger() ]);
      console.log(this.ngRedux.getState());
    }
}

enter image description here

1 个答案:

答案 0 :(得分:0)

问题是当您使用this.ngRedux时,因为ngRedux没有声明为AppModule类的变量。删除this或声明为类变量,例如:

export class AppModule { 
ngRedux : NgRedux;
  constructor(ngRedux: NgRedux<IAppState>) {
    // ngRedux.configureStore(rootReducer, INITIAL_STATE);
    this.ngRedux = ngRedux;
    ngRedux.configureStore(rootReducer, INITIAL_STATE, [ createLogger() ]);
    console.log(this.ngRedux.getState());
  }

}