首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >迭代从您的角度4防火墙数据库中的对象数组

迭代从您的角度4防火墙数据库中的对象数组
EN

Stack Overflow用户
提问于 2017-12-17 16:02:41
回答 1查看 336关注 0票数 0

当我尝试迭代我的数据库时,我得到了一些错误,我尝试了几个答案,但都没有结果。下面是我的

order-details.component.html

代码语言:javascript
复制
<header class="masthead h-75 text-white text-center">
  <div class="overlay"></div>
  <div class="container">
    <div class="home-info">
      <h1 class="cover-heading">Your Order</h1>
    </div>
  </div>
</header>
<hr class="hidden-md-down">
<div class="container" *ngFor="let item of items">
  <div class="row">
    <div class="col-12">
      <table class="table table-xs">
        <tr>
          <th></th>
          <th>Description</th>
          <th class="text-center">Amount</th>
          <th class="text-right">Price</th>
          <th class="text-right">Total</th>
        </tr>
        <tr class="item-row">
          <td> <img [src]=item.product.imageUrl class="thumbnail img-fluid"></td>
          <td>
            <p> <strong>{{ item.product.title }}</strong></p>
          </td>
          <td class="text-right" title="Amount">{{ item.quantity}} </td>
          <td class="text-right" title="Price">{{ item.product.price | currency:'NGN':true }}</td>
          <td class="text-right" title="Total">{{ item.totalPrice | currency:'NGN':true }}</td>
        </tr>
      </table>
    </div>
  </div>
</div>

我的命令-细节。组件。

代码语言:javascript
复制
import { Component, OnInit } from '@angular/core';
import {AngularFireDatabase} from 'angularfire2/database';
import {AuthService} from '../auth.service';
import {OrderService} from '../order.service';
import {ActivatedRoute} from '@angular/router';

@Component({
  selector: 'app-order-details',
  templateUrl: './order-details.component.html',
  styleUrls: ['./order-details.component.css']
})
export class OrderDetailsComponent implements OnInit {
  items = {};
  id;

  constructor( private db: AngularFireDatabase,
               public orderService: OrderService,
               private auth: AuthService,
               private route: ActivatedRoute) {
    this.id = this.route.snapshot.paramMap.get('id');

  }

  ngOnInit() {
    this.items = this.orderService.getOrdersByOrderId(this.id)
      .subscribe(items => {
        this.items = items;
        console.log(this.items);
      });
  }
  // getOrdersByOrderId() from my ORDER.SERVICE.TS
  getOrdersByOrderId(orderId) {
    if (!this.OrdersByOrderId$) {
      this.OrdersByOrderId$ = this.db.list('/orders/' + orderId + '/items');
    }
    return this.OrdersByOrderId$;
  }

}

我从JAVASCRIPT浏览器控制台得到的错误。

无法找到“对象”类型的不同支持对象“对象对象”。NgFor只支持绑定到诸如数组之类的Iterable。在NgForOf.ngOnChanges (common.es5.js:1734)

下面的图片是我来自FIREBASE的数据库树。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-17 17:01:34

只需在ngOnInit()中更改订阅,就可以分配订阅,然后将项重新分配给项。

代码语言:javascript
复制
 ngOnInit() {
     this.orderService.getOrdersByOrderId(this.id)
      .subscribe(items => {
        this.items = items;
        console.log(this.items);
      });
  }

//我已经删除了这个this.items =

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

https://stackoverflow.com/questions/47856894

复制
相关文章

相似问题

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