![](/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.