html - 数据绑定导致 [object Object]
问题描述
我正在尝试将行记录绑定到我的视图。这是我在后端的代码:
[Route("GetCarCount")]
[HttpGet]
public async Task<long> Count()
{
return await _context.Cars.CountAsync();
}
我已经对此进行了测试,并且可以正常工作。我得到一个像数字一样的结果
9
现在我想在视图上绑定它,这是我在服务中的代码。
getCount() {
return this.http.get(this.baseUrl + 'GetCarCount');
}
我这样称呼这个方法:
GetCarCount() {
this.countrecords = this.carservice.getCount();
}
我已经声明了一个这样的变量:
countrecords: any;
现在我像这样绑定它:
<label>Records count: = {{countrecords}}</label>
它不显示数字9
而是我得到[object Object]
我试过这样但它对我不起作用
JSON.parse JSON.stringify
我究竟做错了什么?
解决方案
从你的实现来看,countrecords
将是 type Observable<number>
。使用async
模板中的管道来解开它的值。
<label>Records count: = {{countrecords | async}}</label>
推荐阅读
- python - 复利的熊猫资本化
- saml-2.0 - OneLogin 签名的 Authnrequest HTTP 重定向方法
- python - 如何按名称访问列作为变量以使用 isin() 方法
- vert.x - 如何使用 Vertx 3 使用 SOAP WSDL
- javascript - 如何添加多个反应?
- git - 从最后一次 git 提交中提取块而不重新提交原始提交
- wordpress - 如何将自定义分类法附加到 Wordpress 中的帖子?
- xna - 无法从 XNA Framework C# 上的另一个类接收值
- java - 如何强制 Hibernate 在更新查询中使用 AND?
- sql - 使用 CONVERT 在动态 SQL 中处理 COALESCE