Mysql 如何计算api服务的数据并以角度分量显示在卡中
我想在一张卡片上显示角度项目,例如,行的计数。为了从mysql获取数据,我使用了一个服务 以下是服务数据:Mysql 如何计算api服务的数据并以角度分量显示在卡中,mysql,node.js,angular,Mysql,Node.js,Angular,我想在一张卡片上显示角度项目,例如,行的计数。为了从mysql获取数据,我使用了一个服务 以下是服务数据: private _postsURL = "http://localhost:3003/all"; constructor(private http: Http) { } getcount(): Observable<ICustomer[]> { return this.http .get(this._postsURL) .m
private _postsURL = "http://localhost:3003/all";
constructor(private http: Http) {
}
getcount(): Observable<ICustomer[]> {
return this.http
.get(this._postsURL)
.map((response: Response) => {
return <ICustomer[]>response.json();
})
.catch(this.handleError);
}
component.html
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-12" *ngFor="let post of _count">
<h2 class="m-b-0"><i class="mdi mdi-buffer text-
warning"></i></h2>
<h3 class="">{{post}}</h3>
<h6 class="card-subtitle">Total Earnings</h6>
</div>
<div class="col-12">
<ngb-progressbar [showValue]="false"
type="warning" [value]="50"></ngb-progressbar>
{{post}}
总收入
我只想用从api获取的值填充卡。api响应是一个异步事件,Ngonit方法执行在从后端调用获取响应之前完成,仅当
\u count
变量绑定在其中获得值时,才应呈现卡节视图,您可以通过在根卡html元素上添加ngIf指令来实现该视图,如下所示
<div class="card" *ngIf="_count?.length > 0">
<div class="card-body">
<div class="row">
<div class="col-12" *ngFor="let post of _count">
<h2 class="m-b-0"><i class="mdi mdi-buffer text-
warning"></i></h2>
<h3 class="">{{post}}</h3>
<h6 class="card-subtitle">Total Earnings</h6>
</div>
<div class="col-12">
<ngb-progressbar [showValue]="false"
type="warning" [value]="50"></ngb-progressbar>
{{post}}
总收入
API响应是一个异步事件,Ngonit方法执行在它从后端调用获得响应之前完成,因此,只有当\u count
变量绑定在其中获得值时,才应该呈现卡节视图,并且可以通过在根卡html元素上添加ngIf指令来实现,如下所示
<div class="card" *ngIf="_count?.length > 0">
<div class="card-body">
<div class="row">
<div class="col-12" *ngFor="let post of _count">
<h2 class="m-b-0"><i class="mdi mdi-buffer text-
warning"></i></h2>
<h3 class="">{{post}}</h3>
<h6 class="card-subtitle">Total Earnings</h6>
</div>
<div class="col-12">
<ngb-progressbar [showValue]="false"
type="warning" [value]="50"></ngb-progressbar>
{{post}}
总收入
首先是一个问题,为什么要使用Http
而不是HttpClient
?您应该包括一个当前接收到的数据示例,即,当您控制台记录resultArray响应时有什么?首先是一个问题,为什么要使用Http
而不是HttpClient
?您应该包括当前接收的数据示例,即控制台记录resultArray响应时有什么?错误类型错误:无法读取未定义的属性“length”!此api调用返回一个数字:例如2,我想在cardapp.get(“/all)”,(req,res)=>{const connection=mysql.createConnection({host:'',user:'',password:'',database:'',})const queryString=“SELECT COUNT()作为来自customer
WHERE country='Austria'”connection.query(queryString,(err,rows,fields)=>{}@Alia)的Totali,示例中有一个输入错误,刚刚更正。它应该*ngIf=“\u count?.length>0”
使用类卡中的ngIf,我看不到卡:(错误类型错误:无法读取未定义的属性'length'!此api调用仅返回一个数字:例如2,我希望在cardapp.get(“/all”,(req,res)=>{const connection=mysql.createConnection({主机:“”,用户:“”,密码:“”,数据库:“”,})const queryString=“SELECT COUNT()as Totali FROMcustomer
WHERE country='Austria'”connection.query(queryString,(err,rows,fields)=>{}@Alia示例中有一个输入错误,刚刚更正。它应该*ngIf=“\u COUNT?.length>0”
使用类卡中的ngIf我看不到卡:(