【发布时间】:2021-04-15 10:30:57
【问题描述】:
我在 Angular 管道中使用 array.filter,并导入了我创建的类:
import { Pipe, PipeTransform } from '@angular/core';
import Product from '../models/Product';
@Pipe({
name: 'products'
})
export class ProductsPipe implements PipeTransform {
transform(products: Product[], valueToSearch: string): any {
return products.filter( product => product.name);
}
}
由于某种原因,我收到了这个错误:Property 'name' does not exist on type 'Product',这很有趣,因为它绝对存在于 Product 类型上。
这是第二次使用过滤器,有人可以帮忙吗?
模型:
export default class Product {
public constructor(
ID: number,
name: string,
category: string,
price: number,
imageURL: string
) {};
}
我设法弄明白了,我的模型没有他的“公共”属性。
【问题讨论】:
-
为“../models/Product”添加代码;
-
分享你的模型
标签: angular typescript types