Ionic framework 从服务[4]以html格式呈现JSON
多亏了parrycima,我创建了我的第一个服务 结果.service.tsIonic framework 从服务[4]以html格式呈现JSON,ionic-framework,ionic4,Ionic Framework,Ionic4,多亏了parrycima,我创建了我的第一个服务 结果.service.ts constructor(private httpService: HttpClient) { } async checkFunc() { this.apiurl = 'https://my.apiurl.com/'; this.httpService.get(this.apiurl).subscribe(res => { if (res) {
constructor(private httpService: HttpClient) {
}
async checkFunc() {
this.apiurl = 'https://my.apiurl.com/';
this.httpService.get(this.apiurl).subscribe(res => {
if (res) {
this.items = Object.keys(res).map(function(key) {
return res[key];
});
}
}, (err: HttpErrorResponse) => {
console.log (err.message);
}
);
}
app.component.ts
export class AppComponent {
constructor(
public myService: ResultsService,
private httpService: HttpClient
) {
this.myService.checkFunc();
}
app.component.html
<ion-content>
<ion-list *ngFor="let item of items">
<ion-item>{{item.operator}}
<div class="icon-status" slot="end">
<ion-icon name="{{item.status}}"></ion-icon>
</div>
</ion-item>
</ion-list>
</ion-content>
{{item.operator}}
我只能在控制台模式下获取对象,但不能在HTML呈现模式下获取对象
使用相同的函数,我可以在result.page.ts.中很好地呈现HTML。从您的服务返回此.items
async checkFunc() {
this.apiurl = 'https://my.apiurl.com/';
await this.httpService.get(this.apiurl).subscribe(res => {
if (res) {
this.items = Object.keys(res).map(function(key) {
return res[key];
});
return this.items
}
}, (err: HttpErrorResponse) => {
console.log (err.message);
}
);
}
export class AppComponent {
items;
constructor(
public myService: ResultsService,
private httpService: HttpClient
) {
this.items = this.myService.checkFunc();
}
谢谢你的帮助。获取此错误:AppComponent.html:4错误:找不到类型为“object”的不同支持对象“[object Promise]”。NgFor只支持绑定到数组之类的可重用文件。