首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角2茉莉花误差:不能解析NgRedux的所有参数

角2茉莉花误差:不能解析NgRedux的所有参数
EN

Stack Overflow用户
提问于 2017-04-16 09:09:24
回答 1查看 608关注 0票数 0

我使用的是角度为2的ngRedux

我正在尝试测试一个使用ngRedux的简单组件

代码语言:javascript
复制
import { Component, OnInit } from '@angular/core';
import { NgRedux, select } from 'ng2-redux';
import { CustomerProfileModel, rootReducer } from '../common/customerProfileReducer';

@Component({
  selector: 'app-profile-details',
  templateUrl: './profile-details.component.html',
  styleUrls: ['./profile-details.component.css']
})
export class ProfileDetailsComponent implements OnInit {

  customerUIData: object;

  constructor(
    private ngRedux: NgRedux<Map<string, any>>) {
    this.ngRedux.subscribe(() => {
      this.getDataFromStore()
    })
  }

  ngOnInit() { this.getDataFromStore()}

  getDataFromStore() {
    var store = this.ngRedux.getState();
    this.customerUIData = store;
  }

}

我的单元测试如下:

代码语言:javascript
复制
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NgRedux, select, NgReduxModule } from 'ng2-redux';
import { ProfileDetailsComponent } from './profile-details.component';
import { CustomerProfileModel, rootReducer } from '../common/customerProfileReducer';

describe('ProfileDetailsComponent', () => {
  let component: ProfileDetailsComponent;
  let fixture: ComponentFixture<ProfileDetailsComponent>;
  let ngRedux: NgRedux<CustomerProfileModel>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ProfileDetailsComponent],
      providers: [NgRedux],
      imports:[NgReduxModule]
    })
      .compileComponents();

  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(ProfileDetailsComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });
});

Redux商店如下:

代码语言:javascript
复制
export interface CustomerProfileModel {
    customerData: {
        ....
    };
}

export const CUSTPROFILE_INITIAL_STATE: CustomerProfileModel = {
    customerData: {
        ....
    }
};

export function rootReducer(state: CustomerProfileModel, action) {
    switch (action.type) {
        case 'GET_CUSTOMER_PROFILE_SUCCESS':
          return { customerData: action.customerData };
    }
    return state;
}

我收到的错误如下

代码语言:javascript
复制
Failed: Can't resolve all parameters for NgRedux: (?).

有人能帮我找出我需要的参数吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-16 09:16:14

删除" providers : NgRedux“,因为如果您已经在使用NgReduxModule,则不需要向提供程序添加NgReduxModule。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43435599

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档