【问题标题】:display data in html with angular4使用angular4在html中显示数据
【发布时间】:2019-05-13 23:58:36
【问题描述】:

我正在使用 angular 4 和 springboot 来构建一个应用程序,但我有一个问题,我想在 html 中显示一个计数对象,但我不知道如何 这是我的仓库

@Query("select count (c) from Contact c")
    int getCountOfContact();

我的服务.ts

getContactCount(){
    return this.http.get("http://localhost:9090/contact/count")
      .map(resp=>resp.json());
  }

我的组件.ts

getCountConact(){
  this.dashboardservice.getContactCount().subscribe((data)=>{
    console.log(data);
  },(error)=>{
    console.log(error);
  })
}

如何在我的 component.html 中获得结果

【问题讨论】:

    标签: angular spring-boot


    【解决方案1】:

    真正的问题是什么?您的服务是否返回预期结果?如果是这样,您应该将其保存到变量中,然后您可以将其绑定到 html 中。 组件.ts

    data: any;
    
    getCountConact(){
      this.dashboardservice.getContactCount().subscribe((data)=>{
        this.data = data;
        console.log(data);
      },(error)=>{
        console.log(error);
      })
    }
    

    和html:

    <div>
    {{ result }}
    </div>
    

    【讨论】:

    • 这个解决方案不起作用,我没有任何可变结果
    • 你的http请求有响应吗?
    • 但是当你从你的应用程序中调用它时你会得到响应吗?
    • 那么问题出在您的服务器和客户端之间的连接上。你添加了 proxy.conf 吗?
    • 问题不是服务器和客户端之间的连接,它运行良好我的问题是如何在 html 组件中获取结果,我不知道要为其编写代码
    猜你喜欢
    • 1970-01-01
    • 2019-02-23
    • 1970-01-01
    • 1970-01-01
    • 2016-04-27
    • 2018-01-13
    • 1970-01-01
    • 2017-11-11
    • 2013-12-07
    相关资源
    最近更新 更多