Answer a question

I am using the below versions:

  • @ngrx/effects@8.6.0

  • @ngrx/store@8.6.0

  • @ngrx/core@1.2.0

  • @angular/cli@8.3.25

imports:

import { BookService } from './../services/book.service';
import {Actions, Effect, ofType} from '@ngrx/effects';
import {mergeMap, map} from 'rxjs/operators';
import {Action} from '@ngrx/store';
import * as types from './action.types';
import * as bookActions from './book.actions';

constructor:

constructor(private service: BookService,
        private actions$: Actions){}

@Effect() loadBooks$: Observable<Action> = this.actions$.pipe(
        ofType<bookActions.loadBooksAction>(types.LOAD_BOOKS),
        mergeMap(() => 
            this.service.getAllBooks().pipe(map(books => 
                new bookActions.loadBooksSuccessAction(books)))
        )
    )

The Error: Property 'pipe' does not exist on type 'Actions'.

Answers

First thing ngrx v8 use new syntax so you may want to check it with your code

Sample from the docs

search$ = createEffect(() => ({
  // assign default values
  debounce = 300,
  scheduler = asyncScheduler
} = {}) =>
  this.actions$.pipe(
    ofType(BookActions.search),
    debounceTime(debounce, scheduler),
    ...
  )
);

Secondly remove package-lock.json and @ngrx/core package (no need for this) in your package.json

And update package.json like this

"@ngrx/effects": "^8.6.0",
"@ngrx/store": "^8.6.0",
"@ngrx/store-devtools": "^8.6.0",

Then run

npm cache clean --force
npm i 

You can delete node_modules folder and run npm i if the problem still exist

Logo

React社区为您提供最前沿的新闻资讯和知识内容

更多推荐