首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在html中执行ngFor使对象数组中的对象id未定义。

在html中执行ngFor使对象数组中的对象id未定义。
EN

Stack Overflow用户
提问于 2018-07-18 09:01:17
回答 1查看 77关注 0票数 0

我正在使用离子框架开发一个移动应用程序,我有一个获取事务数据的api调用,我必须在我的html模板中列出事务:

api返回的数据:

代码语言:javascript
复制
[
    {
        amount1:"100",
        buyer_email:null,
        buyer_name:"test",
        confirms_needed:2,
        created_at:"2018-07-09 07:56:33",
        id:8,
        invoice:null,
        currency1: "USD"
    },
    {
        amount1:"100",
        buyer_email:null,
        buyer_name:"test",
        confirms_needed:2,
        created_at:"2018-07-10 04:36:33",
        id:6,
        invoice:null,
        currency1: "USD"
    }
]

发出api调用的类型记录代码:

代码语言:javascript
复制
 ionViewDidLoad() {
    this.transactionProvider.getTransactions()
    .subscribe((data:any)=>{
      this.transactions = data;
      console.log(this.transactions);
    },error=>{
      console.log(error);
    });
  }

我只是在导出类下键入事务来初始化事务。

这就是我在事务数据上循环的方式。

代码语言:javascript
复制
<div class="width-100p  fl-left box-shadow   border-radius-10 padd-tp-bt-10 mg-tp-20" *ngFor="let transaction of transactions">
    <div (click)="saveTransactionClick(transaction)">
        <img width="20" src="assets/imgs/currencies/icons/{{transaction.currency1}}.png">
        <div class="fl-left mg-l-10">
            <div class="f-size-12 width-100p fl-left">{{transaction.currency1}} text: {{transaction.id}} :tet</div>
            <div class="f-size-10 width-100p fl-left gray">{{transaction.created_at | date: 'yyyy-MM-dd'}}</div>
            <div class="f-size-10 width-100p fl-left gray">{{transaction.created_at | date: 'hh:mm:ss'}}</div>
        </div>
    </div>
</div>

现在的问题是,当我console.log(this.transactions)的id是未定义的,但其余的数据是正确的:am装入,buyer_name .

如果我从html中删除ngFor,ids就会恢复正常。

我不知道为什么会发生这种事,我也不知道该如何解决。

更新

错误地使用ngIf错误地使用了

在我的html中,我有一个错误的ngif,当我将*ngIf="transaction.id = clickedTransactionId"改为*ngIf="transaction.id == clickedTransactionId时,我没有意识到它“它工作得很好。

谢谢

EN

回答 1

Stack Overflow用户

发布于 2018-07-19 06:58:49

不久前,我写了一个ngif,它分配id,而不是检查它的值。

*ngIf="transaction.id = clickedTransactionId"

改到

*ngIf="transaction.id == clickedTransactionId"

一切如愿,谢谢大家。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51397803

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档