我正在使用这个种子开发 Angular 2 项目:angular2-webpack-starter我也在使用@ngrx/store & @ngrx/store-devtools .
在引导过程中,应用程序抛出一个错误:
zone.js:260 - Uncaught Invalid provider - only instances of Provider and Type are allowed, got: [object Object]
以下是我如何使用种子设置@ngrx:
将包添加到 vendor.browser.ts
// ngrx
import '@ngrx/core';
import '@ngrx/store';
import 'ngrx-store-router';
if ('production' === ENV) {
// Production
} else {
// Development
require('angular2-hmr');
require('@ngrx/store-devtools');
require('@ngrx/store-log-monitor');
}
为 angular 2 添加提供程序 ( browser-providers.ts
)
// @ngrx/store
import { provideStore } from '@ngrx/store';
// @ngrx/devtools
import { instrumentStore } from '@ngrx/store-devtools';
import { useLogMonitor } from '@ngrx/store-log-monitor';
// link angular's router with ngrx/sotre
import { routerMiddleware } from 'ngrx-store-router';
// custom data for ngrx
import { REDUCERS, initialState } from '../app/shared/redux';
export const APPLICATION_PROVIDERS = [
// awesome redux implementation for angular
provideStore(REDUCERS, initialState),
instrumentStore({
monitor: useLogMonitor({
visible: true,
position: 'right'
})
}),
// link angular's router with ngrx/sotre
routerMiddleware,
//...
];
将监视器添加到我的应用程序模板
<ngrx-store-log-monitor toggleCommand="ctrl-h" positionCommand="ctrl-m"></ngrx-store-log-monitor>
.
简单。
但是当我console.log
什么instrumentStore()
返回,我得到一个对象数组。但是 Angular 需要和一系列的提供者。
这是我的包的版本:
- Angular 2: rc3
- @ngrx/核心:1.0.1
- @ngrx/商店:1.5.0
- @ngrx/store-devtools: 2.0.0-beta1
- @ngrx/store-log-monitor: 2.0.0-beta1
如果有问题,我会在 Github 上报告。但我不确定是否正确设置了所有内容。
谢谢。
最佳答案
问题很简单。
我已将 @ngrx/store
升级到版本 2 (2.0.1),它可以正常工作。
关于typescript - @ngrx/store-devtools : instrumentStore() returns an array of objects instead of providers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38181540/