Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular ngrx/store给我找不到模块'/购物清单/商店/购物清单.reducer“;错误_Angular_Typescript_Ngrx_Ngrx Store - Fatal编程技术网

Angular ngrx/store给我找不到模块'/购物清单/商店/购物清单.reducer“;错误

Angular ngrx/store给我找不到模块'/购物清单/商店/购物清单.reducer“;错误,angular,typescript,ngrx,ngrx-store,Angular,Typescript,Ngrx,Ngrx Store,我只安装了ngrx/store,然后在shopping list/store/shopping list.reducer.ts中创建了reducer import { Ingredient } from '../../shared/ingredient.model'; import * as ShoppingListActions from "./shopping-list.actions"; export const initialState = { ing

我只安装了ngrx/store,然后在shopping list/store/shopping list.reducer.ts中创建了reducer

import { Ingredient } from '../../shared/ingredient.model';
import  * as ShoppingListActions from "./shopping-list.actions";


export const initialState = {
   
 ingredients: [
        new Ingredient('Apples', 5),
        new Ingredient('Tomatoes', 10),
    ]
};

export function shoppingListReducer(state = initialState, action: ShoppingListActions.AddIngredient){
   
switch (action.type) {
     
  case ShoppingListActions.ADD_INGREDIENT:
        
   return {
               ...state,
               ingredients: [
                   ...state.ingredients, action.payload
               ]
           };
   
   }
} 
并在购物列表/商店/购物列表中存储操作。action.ts.

import { Action } from "@ngrx/store";

import { Ingredient } from '../../shared/ingredient.model';


export const ADD_INGREDIENT = 'ADD_INGREDIENT'; 


export class AddIngredient implements Action{

   readonly type = ADD_INGREDIENT;

   payload: Ingredient; 
}
但当我尝试在app.module.ts文件中导入此文件时,它会显示 src/app/app.module.ts:12:37中出错-错误TS2307:找不到模块“./shopping list/store/shopping list.reducer”。 12从“./shopping list/store/shopping list.reducer”;”导入{shoppingListReducer}此类错误

这是我的app.module.ts文件

import { BrowserModule } from '@angular/platform-browser';


import { NgModule } from '@angular/core';

import { HttpClientModule } from '@angular/common/http';



import { AppComponent } from './app.component';

import { HeaderComponent } from './header/header.component';

import { AppRoutingModule } from './app-routing.module';

import { SharedModule } from './shared/shared.module';

import { CoreModule } from './core.module';


import { ErrorPageModule } from './error-page/error-page.module';

import { StoreModule } from '@ngrx/store'; 

import { shoppingListReducer } from './shopping-list/store/shopping-list.reducer';


@NgModule({

  declarations: [AppComponent, HeaderComponent],

  imports: [

    BrowserModule,

    HttpClientModule,

    StoreModule.forRoot({ shoppingList: shoppingListReducer }),

    AppRoutingModule,

    SharedModule,

    CoreModule,

    ErrorPageModule,

  ],

  bootstrap: [AppComponent],

  providers: []

})

export class AppModule {}

我是否需要为此安装任何额外的内容,并且“@ngrx/store”:“^9.2.0”已安装。请确保导入的路径正确无误

import { Action } from "@ngrx/store";

import { Ingredient } from '../../shared/ingredient.model';


export const ADD_INGREDIENT = 'ADD_INGREDIENT'; 


export class AddIngredient implements Action{

   readonly type = ADD_INGREDIENT;

   payload: Ingredient; 
}
例如,试试看

import { shoppingListReducer } from '../shopping-list/store/shopping-list.reducer';

您还可以删除导入,让IDE来解决它。

可以尝试:
import*as shoppingListReducer from./shopping list/store/shopping list.reducer'已成功解析。非常感谢。