[英]The @component in pipes not working angular2
I don't know about the component in pipes:我不知道管道中的组件:
[] error [] 错误
[error message ] Argument of type '{ selector: string; [错误消息] '{选择器:字符串; templateUrl: string;
模板网址:字符串; pipes: any[];
管道:任何[]; }' is not assignable to parameter of type 'Component'.
}' 不可分配给“组件”类型的参数。 Object literal may only specify known properties, and 'pipes' does not exist in type 'Component'.
对象字面量只能指定已知属性,并且“组件”类型中不存在“管道”。
notice-list.component.ts通知列表.component.ts
import {Component, OnInit} from '@angular/core';
import {ocNotice} from './product';
import {NoticeFilterPipe} from './product-filter.pipe';
import {NoticeService} from './product.service'
@Component({
selector : 'pm-products',
templateUrl : './app/products/product-list.component.html',
pipes: [ noticeFilter ]
})
export class ProductListComponent{
pageTitle : string = 'Notice List';
imgW : number = 30;
imgH : number = 30;
showImage : boolean = false;
listFilter : string;
notice : ocNotice[];
constructor(private _noticeService : NoticeService){
}
toggleImage() : void{
this.showImage = !this.showImage;
}
ngOnInit() : void{
console.log("Oninit");
this.notice = this._noticeService.getProduct();
}
product-filter.pipe.ts产品filter.pipe.ts
import {PipeTransform, Pipe} from '@angular/core';
import {ocNotice} from './product';
@Pipe({
name : 'noticeFilter'
})
export class NoticeFilterPipe implements PipeTransform{
transform(value : ocNotice[], args : string) : ocNotice[]{
let filter : string = args[0] ? args[0].toLocaleLowerCase() : null;
return filter ? value.filter((notice : ocNotice) =>
notice.title.toLocaleLowerCase().indexOf(filter) != -1) : value;
}
}
if you get this error:如果您收到此错误:
Argument of type '{ selector: string; '{选择器:字符串; templateUrl: string;
模板网址:字符串; pipes: typeof MattDamon[];
管道:MattDamon[] 的类型; }' is not assignable to parameter of type 'Component'.
}' 不可分配给“组件”类型的参数。 Object literal may only specify known properties, and 'pipes' does not exist in type 'Component'.
对象字面量只能指定已知属性,并且“组件”类型中不存在“管道”。
Instead of adding the pipe in pipes[] array in the @component, add the pipe in the 'declarations' array inside 'app.modules.ts', and no need to use 'pipes' array不是在@component 中的pipes[] 数组中添加管道,而是在'app.modules.ts' 内的'declarations' 数组中添加管道,而无需使用'pipes' 数组
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.