gpt4 book ai didi

javascript - 无法在模板中显示值

转载 作者:行者123 更新时间:2023-12-02 23:04:19 26 4
gpt4 key购买 nike

我已经成功检索了 JSON 数据,但我似乎找不到像其他人那样输出该值的方法。想知道我的模板中显示值的方式出了什么问题吗?

函数如下,

getUserInfo() {
var service = this;
let url = service.appConfig.Shop_URL + "/wp-json/wp/v2/users/" + service.userService.id;
url = this.initUrl(url, '');
var headers = new Headers();
headers.append('Authorization', 'Bearer ' + service.userService.token);
headers.append('Content-Type', 'application/json');
return new Promise(function (resolve, reject) {
service.http.get(url, { headers: headers }).pipe(map(res => res.json())).subscribe(data => {
if (data) {
service.cachedData = data;
console.log(data);
resolve(service.cachedData);
}
else {
reject();
}
});

});
}

listUserDetails() {
this.getUserInfo().then((data: Array<any>) => {
this.user_details = data;
console.log(this.user_details);
});
}

在控制台中数据显示如下,

{id: 584, name: "test", url: "", description: "", link: "https://oc.xxxxx.com/author/test/", …}
avatar_urls: {24: "https://secure.gravatar.com/avatar/b642b4xxx", 48: "https://secure.gravatar.com/avatar/b642b4xxx", 96: "https://secure.gravatar.com/avatar/b642bxxxx"}
commission_earned: "36"
commission_rate: "5"
daily_sales: "720"
description: ""
id: 584
link: "https://oc.xxxxx.com/author/test/"
meta: []
name: "test"
slug: "test"
url: ""

在我的模板中,我使用了以下方法,但它没有返回值。

<span *ngFor="let detail of user_details">{{detail.daily_sales}}</span>

提前致谢。

最佳答案

您可能只需要像处理对象而不是数组一样处理 user_details

所以改变

<span *ngFor="let detail of user_details">{{detail.daily_sales}}</span>

<span >{{user_details.daily_sales}}</span>

有关 *ngFor 的更多信息:https://angular.io/api/common/NgForOf

关于javascript - 无法在模板中显示值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57658794/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com