简体   繁体   中英

ngFor loop is hitting an undefined and stopping

*ngFor is hitting an undefined value and stopping, how do I tell it to keep going? ... when I take out {{order.shipping.name}} the other two interpolations work.

the component:

import { Observable } from 'rxjs/Observable';
import { Component } from '@angular/core';
import { OrderService } from '../../order.service';
import { FirebaseListObservable } from 'angularfire2/database-deprecated';

@Component({
    selector: 'app-admin-orders',
    templateUrl: './admin-orders.component.html',
    styleUrls: ['./admin-orders.component.css']
})
export class AdminOrdersComponent {
    orders$;

    constructor(private orderService: OrderService) {
        this.orders$ = orderService.getOrders();
    }

}

the template:

<table class="table table-striped table-bordered table-hover">
    <thead>
        <tr>
            <th>date</th>

            <th class="text-center">id</th>
            <th class="text-right">id</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                <div *ngFor="let order of this.orders$ | async: date">
                    {{order.shipping.name}}

                </div>
            </td>
            <td class="text-center">
                <div *ngFor="let order of this.orders$ | async">

                    {{order.datePlaced | date:"short"}}
                    <!-- https://angular.io/api/common/DatePipe -->
                </div>
            </td>
            <td class="text-right">
                <div *ngFor="let order of this.orders$ | async">
                    <a> {{order.userId}} </a>

                </div>
            </td>
        </tr>
    </tbody>
</table>

I looked here and changed it to...

orders$: FirebaseListObservable<any>; in the component

{{order?.shipping.name}} in the template

...with no luck

运送后,您还需要其他安全的导航操作员,

 {{order?.shipping?.name}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM