Я не знаю, о компоненте в трубах:@component в трубах не работает angular2
[] ошибка
[сообщение об ошибке] Аргумент типа «{селекторного: строка; templateUrl: string; трубы: любые []; } 'не присваивается параметру типа «Компонент». Литерал объекта может указывать только известные свойства, а «pipe» не существует в типе «Компонент».
уведомление-list.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();
}
продакт-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;
}
}
Вы вводите трубку неправильно. Прочтите мой ответ и следуйте инструкциям: http://stackoverflow.com/questions/42093552/can-i-make-global-registration-pipe-guard-for-global-access/42094880#42094880 –
Прежде всего, вы должны объявить 'pipe в вашем' модуле'. Теперь, если вы притворяетесь, что используете 'pipe' в вашем файле' .ts - component', вы должны изменить It: 'pipes: [noticeFilter]' to: 'providers: [NoticeFilterPipe]'. Если вы хотите использовать его в * template *, вам просто нужно объявить его в своем «модуле». – developer033
Что такое версия Angular 2, которую вы используете? Как я знаю, 'pipe' больше не объявляется в' component' файле; его необходимо объявить в 'декларации'' module'. –