Angular / NGRX中断输出

时间:2018-10-31 09:41:03

标签: angular typescript ngrx

我有这个简单的代码,我只是尝试在模块中添加一个reducer。

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 })

我的页面变成空白并且没有'Hello!'一句话,控制台中没有错误。

我的库版本:

  "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"
  },

我怎么知道正在发生什么? 可能我需要在我的reducer中添加一些其他功能吗?

1 个答案:

答案 0 :(得分:0)

谢谢。 将angular更新到最新版本后,效果很好。