Angular 角度5:Can';t解析RouterEffects的所有参数:(?,?,?)
我的应用程序中的路由未按预期工作。我做错什么了吗 使用角度v5。我搜索了很多,但没有一个答案对我有用 任何建议都会有帮助 未捕获错误:无法解析RouterEffects:(?,?,?)的所有参数 app.routing.ts product.module.ts home.module.ts 路线1.tsAngular 角度5:Can';t解析RouterEffects的所有参数:(?,?,?),angular,angular-router,Angular,Angular Router,我的应用程序中的路由未按预期工作。我做错什么了吗 使用角度v5。我搜索了很多,但没有一个答案对我有用 任何建议都会有帮助 未捕获错误:无法解析RouterEffects:(?,?,?)的所有参数 app.routing.ts product.module.ts home.module.ts 路线1.ts import { Location } from '@angular/common'; import { Injectable } from '@angular/core'; import {
import { Location } from '@angular/common';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Actions, Effect, ofType } from '@ngrx/effects';
import { map, tap } from 'rxjs/operators';
import { RouterActionTypes, Go } from '../actions';
@Injectable()
export class RouterEffects {
@Effect({ dispatch: false })
navigate$ = this.actions$
.pipe(
ofType<Go>(RouterActionTypes.Go),
map(action => action.payload),
tap(({ commands, extras }) => this.router.navigate(commands, extras))
)
@Effect({ dispatch: false })
navigateBack$ = this.actions$
.pipe(
ofType(RouterActionTypes.Back),
tap(() => this.location.back())
);
@Effect({ dispatch: false })
navigateForward$ = this.actions$
.pipe(
ofType(RouterActionTypes.Forward),
tap(() => this.location.forward())
);
constructor(
private actions$: Actions,
private location: Location,
private router: Router
) {}
}
从'@angular/common'导入{Location};
从“@angular/core”导入{Injectable};
从'@angular/Router'导入{Router};
从'@ngrx/effects'导入{Actions,Effect,of type};
从“rxjs/operators”导入{map,tap};
从“../actions”导入{RouterActionTypes,Go};
@可注射()
导出类路由效果{
@效果({dispatch:false})
导航$=this.actions$
.烟斗(
ofType(RouterActionTypes.Go),
映射(action=>action.payload),
点击({commands,extras})=>this.router.navigate(commands,extras))
)
@效果({dispatch:false})
navigateBack$=this.actions$
.烟斗(
ofType(RouterActionTypes.Back),
轻触(()=>this.location.back())
);
@效果({dispatch:false})
navigateForward$=this.actions$
.烟斗(
ofType(RouterActionTypes.Forward),
点击(()=>this.location.forward())
);
建造师(
私有操作$:操作,
私人场所:场所,
专用路由器
) {}
}
您在任何地方都有RouterEffects
课程吗?如果是这样,请在这里发布。这是一个错误,当RouterEffects类中缺少可注入的装饰器时,人们会预料到这个错误。情况似乎并非如此,因此我将检查根模块中的StoreModule.forRoot()之后是否存在EffectsModule.forRoot([])导入。
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FlexLayoutModule } from '@angular/flex-layout';
import { RouterModule, Routes } from '@angular/router';
import { ProductComponent } from './product.component';
import { ProductDetailComponent } from './product-detail';
import { ProductSuggestionComponent } from './product-suggestion';
const routes: Routes = [
{ path: '', component: ProductComponent }
];
@NgModule({
imports: [
CommonModule,
FlexLayoutModule,
RouterModule.forChild(routes),
],
declarations: [
ProductComponent,
ProductDetailComponent,
ProductSuggestionComponent
],
exports: [RouterModule]
})
export class ProductModule {
}
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FlexLayoutModule } from '@angular/flex-layout';
import { RouterModule, Routes } from '@angular/router';
import { EffectsModule } from '@ngrx/effects';
import { StoreModule } from '@ngrx/store';
import { CategoriesComponent } from './categories/categories.component';
import { ProductGridComponent } from './product-grid/product-grid.component';
import { SearchComponent } from './search/search.component';
import { CategoriesEffects, ProductsEffects, reducers } from './store';
const routes: Routes = [
{ path: '', pathMatch: 'full', redirectTo: 'categories' },
{ path: 'search', component: SearchComponent },
{
path: 'categories',
children: [
{ path: '', pathMatch: 'full', redirectTo: 'all' },
{ path: ':category', component: CategoriesComponent }
]
}
];
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(routes),
FlexLayoutModule,
StoreModule.forFeature('home', reducers),
EffectsModule.forFeature([ CategoriesEffects, ProductsEffects ])
],
declarations: [
CategoriesComponent,
ProductGridComponent,
SearchComponent
],
exports: [RouterModule]
})
export class HomeModule {
}
import { Location } from '@angular/common';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Actions, Effect, ofType } from '@ngrx/effects';
import { map, tap } from 'rxjs/operators';
import { RouterActionTypes, Go } from '../actions';
@Injectable()
export class RouterEffects {
@Effect({ dispatch: false })
navigate$ = this.actions$
.pipe(
ofType<Go>(RouterActionTypes.Go),
map(action => action.payload),
tap(({ commands, extras }) => this.router.navigate(commands, extras))
)
@Effect({ dispatch: false })
navigateBack$ = this.actions$
.pipe(
ofType(RouterActionTypes.Back),
tap(() => this.location.back())
);
@Effect({ dispatch: false })
navigateForward$ = this.actions$
.pipe(
ofType(RouterActionTypes.Forward),
tap(() => this.location.forward())
);
constructor(
private actions$: Actions,
private location: Location,
private router: Router
) {}
}