angular - 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"
},
我怎样才能弄清楚发生了什么?可能我需要在我的减速器中添加一些额外的功能?
解决方案
谢谢你。将角度更新到最新版本后,它工作正常。
推荐阅读
- java - 给定各种温度输入,如何确定归一化温度?
- machine-learning - 多层感知器的恒定损失(Python)
- android - 将活动添加到底部导航栏 - 尝试调用虚拟方法 'void com.google.android.material.bottomnavigation
- java - 在 Java 中比较两个对象与 int 和 string 参数
- javascript - 为什么我的可注入角度服务类没有按预期保存类变量?
- java - 编写 Classes 类然后实现它们
- javascript - 是否可以同时更改克隆和原始元素?- jQuery
- java - 在运行时将类从一个更改为另一个
- sql - 获取 Max(Amount) 和关联的类型
- reactjs - 在反应 js 中切换显示/隐藏 li 上的“活动”类