Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql SQL COUNT()和_Mysql_Angular_Count - Fatal编程技术网

Mysql SQL COUNT()和

Mysql SQL COUNT()和,mysql,angular,count,Mysql,Angular,Count,使用Angular显示SQL命令(Count())时出现问题 PHP文件(此文件没有问题): 但要以角度显示它: 动物服务 getNbAnimals(idA: number){ return this.http.get(this.apiUrl + '/animal/' + idA + '/nb'); } 动物成分 getNbAnimals(idA: number){ this.animalService.getNbAnimals(idA); } animal.component.html

使用Angular显示SQL命令(Count())时出现问题

PHP文件(此文件没有问题):

但要以角度显示它:

动物服务

getNbAnimals(idA: number){ return this.http.get(this.apiUrl + '/animal/' + idA + '/nb'); }
动物成分

 getNbAnimals(idA: number){ this.animalService.getNbAnimals(idA); }
animal.component.html

<p>{{getNbAnimals(idAnimal.value)}}</p>
{{getnbanimal.value)}

此HTML文件的结果是[object]。我不知道如何显示我的计数()。
如果你能帮助我,谢谢你

这是因为您试图显示该函数返回的内容,这通常是可观察的。相反,尝试以下方法:

<p>{{getNbAnimals(idAnimal.value) | async}}</p>

我想你有一件东西

 this.http.get(this.apiUrl + '/animal/' + idA + '/nb');
所以在返回之前只需多做一步

 phpObj = this.http.get(this.apiUrl + '/animal/' + idA + '/nb');
 //and then return object property value
 return phpObj.nbTotal;
或者,您可以修复php响应以仅返回值而不返回数组:

 return json_encode($animalCount['nbTotal']);

谢谢你的回答!首先,TS文件不“知道”nbTotal。第二个也会解决同样的问题。我不知道如何将对象返回转换为简单的数字返回。我怀疑只是在php端将返回更改为:
return$animalCount['nbTotal']
@Thomas check这篇文章:谢谢你的回答我尝试了异步和订阅,但我浏览器的控制台每秒钟都会显示一个接一个的错误,我无法显示“nbTotal”。
 phpObj = this.http.get(this.apiUrl + '/animal/' + idA + '/nb');
 //and then return object property value
 return phpObj.nbTotal;
 return json_encode($animalCount['nbTotal']);