簡體   English   中英

管道中的@component 不工作 angular2

[英]The @component in pipes not working angular2

我不知道管道中的組件:

[] 錯誤

[錯誤消息] '{選擇器:字符串; 模板網址:字符串; 管道:任何[]; }' 不可分配給“組件”類型的參數。 對象字面量只能指定已知屬性,並且“組件”類型中不存在“管道”。

通知列表.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;
    }
}

如果您收到此錯誤:

'{選擇器:字符串; 模板網址:字符串; 管道:MattDamon[] 的類型; }' 不可分配給“組件”類型的參數。 對象字面量只能指定已知屬性,並且“組件”類型中不存在“管道”。

不是在@component 中的pipes[] 數組中添加管道,而是在'app.modules.ts' 內的'declarations' 數組中添加管道,而無需使用'pipes' 數組

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM