![](/img/trans.png)
[英]"TypeError: Cannot convert undefined or null to object at Function.entries" Error when using Cloud Functions
[英]NgRx throws 'TypeError: undefined is not a non-null object' when creating effect
我正在使用和學習 Angular 15,我有這個可注射的 class,它創建了一個 NgRx 效果來將數據存儲在 firebase 數據庫中,但它拋出未定義。
constructor(private actions$: Actions, private http: HttpClient) {}
fetchRecipes = createEffect((): any => {
this.actions$.pipe(
ofType(RecipesActions.FETCH_RECIPES),
switchMap(() => {
return this.http.get<Recipe[]>
(
'https://recipebook-re-default-rtdb.europe-west1.firebasedatabase.app/recipes.json',
)
}),
map(recipes => {
return recipes.map(recipe => {
return {
...recipe,
ingredients: recipe.ingredients ? recipe.ingredients : []
};
});
}),
map(recipes => {
return new RecipesActions.SetRecipes(recipes);
})
);
});
我是 angular 的初學者,我在一門課程之后做了這個效果,也許課程有點過時並且有些東西已被棄用,但我無法弄清楚。
編輯: GitHub 上的代碼(對不起,無法讓stacblitz工作)
我覺得很愚蠢,問題是我沒有返回this.actions$.pipe()
所以它畢竟沒有返回任何東西......
constructor(private actions$: Actions, private http: HttpClient) {}
fetchRecipes = createEffect((): any => {
return this.actions$.pipe(...)
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.