javascript - 将新对象推入数组 angular 7 后视图没有更新?
问题描述
app.component.ts
import { Component, NgZone } from '@angular/core';
import { ApiService } from './api.service';
import configData from './apiConfig.json';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
data: any = [];
finalResponse: any = [];
isLoadingResults = true;
apiConfig = configData;
private _apis: any = [];
constructor(private api: ApiService, private ngZone: NgZone) {
}
// ngOnInit() {
// this._apis.push({name: "getRefills"});
// }
getMemberInfoCache(tokenId) {
console.log(tokenId);
this.api.getProducts(tokenId)
.subscribe((res: any) => {
/** @namespace res.details.cacheobject.specialtyMemberInfo **/
this.data = res.details.cacheobject.specialtyMemberInfo;
console.log("testDATA" , this.data);
this.isLoadingResults = true;
}, err => {
console.log(err);
this.isLoadingResults = false;
});
}
loadApis(tokenId) {
/** @namespace this.apiConfig._apisJson.getRefillsRequest **/
const getRefillRequest = this.apiConfig._apisJson.getRefillsRequest;
console.log("GETREFILLS", getRefillRequest);
if(getRefillRequest) {
// this._apis.push({name: "getRefills"});
// console.log("INSIDE IF", getRefillRequest);
this.ngZone.run(() => { this._apis.push({name: "getRefills" }); })
}
return this._apis;
}
}
app.comp.html
<div class="card-body">
<div class="container">
<table class="table table-striped">
<thead>
<tr>
<th scope="col">Api</th>
<th scope="col">Request</th>
<th scope="col">Status</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of _apis">
<td>
{{item.name}}
</td>
</tr>
</tbody>
</table>
</div>
</div>
解决方案
推荐阅读
- ms-access - 访问计算数字字段:模数问题
- airflow - Airflow - 为某些端点返回 405 的实验性 API
- latex - Latex 引用单独的 PDF
- google-apps-script - 根据谷歌工作表中基本工作表中的范围从模板工作表创建新工作表
- python - 使用 Cookie 和机器学习检查机器人流量
- r - 在水平绘图子图中共享 x 轴标签
- reactjs - 如何以编程方式检查 Material-UI 复选框?
- node.js - 单个数组中两个查询的索引结果,使用expressjs mysql,nodejs
- sbt - sbt 程序集:去重 module-info.class
- java - SpringBoot:从@RequestMapping 控制异步行为类似于AsyncWebServlet?