角管给予价值(品牌)undefiend

时间:2018-05-16 03:51:49

标签: angular pipe angular-pipe

您好我正在尝试为复选框创建角度过滤器。但在控制台中,它是brand is undefined。可能是什么问题 -

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'selectBrand'
})
export class SelectBrandPipe implements PipeTransform {

  transform(brand: any, brandType?: any): any {
    console.log('brand', brandType);
    if (!brandType || brandType.length === 0) return brand;
    return brand.filter(brandName => 
    brandType.includes(brandName.companyName));
  }
}

我使用的过滤器 -

<div class="col-md-4" *ngFor="let product of prod.product | selectBrand: brandType">

如果您需要更多信息,请与我们联系。

已添加 -

我的店铺组件 -

import { Component, OnInit } from '@angular/core';
import { ProductService } from '../services/product.service';
import { Products } from '../data/products';
import { RouterModule, Routes } from '@angular/router';
import { Router, ActivatedRoute, ParamMap } from '@angular/router';
import { PricerangePipe } from '../pipes/pricerange.pipe';
import { PricerangeMaxPipe } from '../pipes/pricerange-max.pipe';
import { SelectBrandPipe } from '../pipes/select-brand.pipe';

@Component({
  selector: 'app-shop',
  templateUrl: './shop.component.html',
  styleUrls: ['./shop.component.scss']
})
export class ShopComponent implements OnInit {
productList: Products[];
productListShow = [];
minPrice: number = 0;
maxPrice: number = 1100;
brandName: string;

constructor(private productservice: ProductService, private activatedRoute: ActivatedRoute) { }

ngOnInit() {
    this.productList = this.productservice.getProducts();
    this.productListShow = this.productList;


this.activatedRoute.params
    .subscribe(params => {
      if (params.type === 'jeans') {
         this.productListShow = this.productList.filter(product=> product.productCat == 'Jeans');
         console.log('productListShow');
      } else if(params.type === 'shirts') {
         this.productListShow = this.productList.filter(product=> product.productCat == 'Shirts');
      } else if(params.type === 'watches') {
         this.productListShow = this.productList.filter(product=> product.productCat == 'Watches');
      }
    });

 }

}

我从组件中删除了一些代码,因为它与此问题无关

我的控制台日志屏幕截图 - enter image description here

0 个答案:

没有答案