【发布时间】:2019-03-25 05:34:57
【问题描述】:
我正在尝试显示包含所有产品的页面和包含类别的部分,但只有类别正在呈现。
我没有在页面上看到产品。
控制台显示错误:
main.653279d3d097093b55e7.js:1 ERROR Error: InvalidPipeArgument: '[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]' for pipe 't'
我的代码:
import { Component, OnInit } from '@angular/core';
import { ProductService } from '../product.service';
import { Observable, Subscription } from 'rxjs';
import { AngularFireList } from 'angularfire2/database';
import { map, switchMap, filter } from 'rxjs/operators';
import { CategoryService } from '../category.service';
import { ActivatedRoute } from '@angular/router';
import { Product } from '../models/product';
@Component({
selector: 'app-products',
templateUrl: './products.component.html',
styleUrls: ['./products.component.css']
})
export class ProductsComponent implements OnInit {
products: any = {};
productsRef: AngularFireList<any>;
filteredProducts;
categories: Observable<any>;
categoriesRef: AngularFireList<any>;
category;
constructor(route: ActivatedRoute, private productService: ProductService, private categoryService: CategoryService) {
this.productsRef = productService.getAll();
this.products = this.productsRef.snapshotChanges().pipe(
map(changes =>
changes.map(c => ({key: c.payload.key, ...c.payload.val() }))
)).switchMap (products => {
this.products = products;
return route.queryParamMap;
}).subscribe (params => {
this.category = params.get('category');
this.filteredProducts = (this.category) ?
this.products.filter(p => p.category === this.category) : this.products;
});
this.categoriesRef = this.categoryService.getAll();
this.categories = this.categoriesRef.snapshotChanges().pipe(
map(changes =>
changes.map(c => ({key: c.payload.key, ...c.payload.val() }))
)
);
有解决此问题的建议吗?
【问题讨论】:
-
向我们展示您用于显示数据的
pipe的代码 -
getAll() { return this.db.list('/products'); }
标签: angular typescript firebase angular5