首页 > 解决方案 > Angular/NGRX 中断输出

问题描述

我有这个简单的代码,我试图在模块中添加一个减速器。

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { StoreModule } from '@ngrx/store';
import {Action} from '@ngrx/store';
import { Component } from '@angular/core';

class Book {
  id: number;
  name: string;
}

class BookStore {
  books: Book[];
}


const ADD_BOOK = '[Book] Add book'; 


export function addReducer(state = BookStore, action: Action) {
  console.log(state, action);

  switch (action.type) {

  }
}


@Component({
  selector: 'app-root',
  template: '<h1>Hello!</h1>',

})
export class AppComponent {
  title = 'app';
}



@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    StoreModule.forRoot({ count: addReducer })
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

一旦我添加了这行代码

StoreModule.forRoot({ count: addReducer })

我的页面变成空的,没有“你好!” word,我在控制台中看不到任何错误。

我的库版本:

  "dependencies": {
    "@angular/animations": "^4.2.4",
    "@angular/common": "^4.2.4",
    "@angular/compiler": "^4.2.4",
    "@angular/core": "^4.2.4",
    "@angular/forms": "^4.2.4",
    "@angular/http": "^4.2.4",
    "@angular/platform-browser": "^4.2.4",
    "@angular/platform-browser-dynamic": "^4.2.4",
    "@angular/router": "^4.2.4",
    "@ngrx/effects": "^6.1.0",
    "@ngrx/store": "^6.1.0",
    "core-js": "^2.4.1",
    "rxjs": "^5.4.2",
    "zone.js": "^0.8.14"
  },

我怎样才能弄清楚发生了什么?可能我需要在我的减速器中添加一些额外的功能?

标签: angulartypescriptngrx

解决方案


谢谢你。将角度更新到最新版本后,它工作正常。


推荐阅读