angular5 中的 Http 响应问题

英杜维拉尤塔姆

我正在从头开始学习 angular 5。我对 Http 响应有一些问题。我无法使用 get() 获取数据。

      getRecipes() {this.http.get('https://indhu-project-45b73.firebaseio.com/recipes.json')
          .subscribe(response => {
           const recipes: Recipe[] = response;
          this.recipeService.setRecipes(recipes);
          });

我已经提供了进口,

  import {Injectable} from '@angular/core';
  import {HttpClient} from '@angular/common/http';
  import {RecipeService} from '../recipes/recipe.service';
  import 'rxjs/add/operator/map';
  import {Recipe} from '../recipes/recipe.model';

  setRecipes(recipes: Recipe[]) {
   this.recipes = recipes;
   this.recipesChanged.next(this.recipes.slice());
   }

我知道我的结局一定有一些基本的错误。有人可以帮助我吗。我收到以下错误

     "Type 'Object' is not assignable to type 'Recipe[]'.
      The 'Object' type is assignable to very few other types. Did you 
       mean to use the 'any' type instead?
      src/app/shared/data-storage.service.ts(17,15): error TS2322: Type 
      'Object' is not assignable to type 'Recipe[]'.
       The 'Object' type is assignable to very few other types. Did you 
        mean to use the 'any' type instead?
        Property 'includes' is missing in type 'Object'."
萨克沙姆·古普塔

这是因为您的响应类型是Object,因此您不能将其分配给Recipe[]类型的配方。您可以改用“any”类型作为回复。然后它会起作用。

getRecipes() {this.http.get('https://indhu-project-45b73.firebaseio.com/recipes.json')
      .subscribe((response: any) => {
       const recipes: Recipe[] = response;
      this.recipeService.setRecipes(recipes);
      });

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

事件响应中的问题

来自分类Dev

在Angular工厂中从HTTP返回响应数据

来自分类Dev

Angular 1.2中$ http服务的问题

来自分类Dev

如何在Angular $ http响应中捕获格式错误的JSON?

来自分类Dev

Angular-$ scope无法访问服务中的$ http响应

来自分类Dev

如何从Angular $ http中删除url协议获取响应

来自分类Dev

Angular:如何在缓慢的HTTP响应中显示某些内容

来自分类Dev

响应中的http.get和Null类型出现问题

来自分类Dev

如何在Angular $ http响应中捕获格式错误的JSON?

来自分类Dev

简单的Angular JS $ http对象响应有问题吗?

来自分类Dev

Angularjs返回问题以响应$ http

来自分类Dev

Angular-$ scope无法访问服务中的$ http响应

来自分类Dev

Angular 2 中的 HTTP GET 触发了在我的 HTTP POST 中收到的用于登录的响应

来自分类Dev

Angular5 RXJS 递归 http 请求

来自分类Dev

如何将 http.post 返回的简单字符串值设置为 Angular5 中的变量

来自分类Dev

从 Angular5 http.get 返回 observable

来自分类Dev

预检响应在 chrome 中具有无效的 http 状态代码 405 angular 5

来自分类Dev

Angular5,在 *ngif 中引用 dom 元素的问题

来自分类Dev

Angular 5 Http api 请求在 chrome 开发工具中获得响应但不会返回

来自分类Dev

Angular5 使用模块中的组件

来自分类Dev

测试在组件 Angular5 中调用 http 服务的函数

来自分类Dev

angular5 在模式中从列表中添加或编辑项目

来自分类Dev

Angular HTTP get 中的 Corrs 问题

来自分类Dev

通过 Angular 6 中的嵌套值过滤 HTTP JSON 响应

来自分类Dev

如何在 Angular 中处理捕获 HTTP 响应?

来自分类Dev

Angular 7 Http 响应

来自分类Dev

在 Angular 中解码 http 响应 - JSON.parse 问题

来自分类Dev

Angular 中的登录和 HTTP POST 问题

来自分类Dev

将 http 响应映射到 angular 7 中的接口

Related 相关文章

  1. 1

    事件响应中的问题

  2. 2

    在Angular工厂中从HTTP返回响应数据

  3. 3

    Angular 1.2中$ http服务的问题

  4. 4

    如何在Angular $ http响应中捕获格式错误的JSON?

  5. 5

    Angular-$ scope无法访问服务中的$ http响应

  6. 6

    如何从Angular $ http中删除url协议获取响应

  7. 7

    Angular:如何在缓慢的HTTP响应中显示某些内容

  8. 8

    响应中的http.get和Null类型出现问题

  9. 9

    如何在Angular $ http响应中捕获格式错误的JSON?

  10. 10

    简单的Angular JS $ http对象响应有问题吗?

  11. 11

    Angularjs返回问题以响应$ http

  12. 12

    Angular-$ scope无法访问服务中的$ http响应

  13. 13

    Angular 2 中的 HTTP GET 触发了在我的 HTTP POST 中收到的用于登录的响应

  14. 14

    Angular5 RXJS 递归 http 请求

  15. 15

    如何将 http.post 返回的简单字符串值设置为 Angular5 中的变量

  16. 16

    从 Angular5 http.get 返回 observable

  17. 17

    预检响应在 chrome 中具有无效的 http 状态代码 405 angular 5

  18. 18

    Angular5,在 *ngif 中引用 dom 元素的问题

  19. 19

    Angular 5 Http api 请求在 chrome 开发工具中获得响应但不会返回

  20. 20

    Angular5 使用模块中的组件

  21. 21

    测试在组件 Angular5 中调用 http 服务的函数

  22. 22

    angular5 在模式中从列表中添加或编辑项目

  23. 23

    Angular HTTP get 中的 Corrs 问题

  24. 24

    通过 Angular 6 中的嵌套值过滤 HTTP JSON 响应

  25. 25

    如何在 Angular 中处理捕获 HTTP 响应?

  26. 26

    Angular 7 Http 响应

  27. 27

    在 Angular 中解码 http 响应 - JSON.parse 问题

  28. 28

    Angular 中的登录和 HTTP POST 问题

  29. 29

    将 http 响应映射到 angular 7 中的接口

热门标签

归档