首页 文章

管道中的@component不工作angular2

提问于
浏览
2

我不知道管道中的组件:

[]错误

[错误消息]类型'{selector:string; templateUrl:string;管道:任何[]; }'不能分配给'Component'类型的参数 . 对象文字只能指定已知属性,“组件”类型中不存在“管道” .

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

1 回答

  • 1

    如果你收到这个错误:

    类型'{selector:string; templateUrl:string;管道:typeof MattDamon []; }'不能分配给'Component'类型的参数 . 对象文字只能指定已知属性,“组件”类型中不存在“管道” .

    不要在@component中的pipes []数组中添加管道,而是在“app.modules.ts”内的'declarations'数组中添加管道,而不需要使用'pipes'数组

相关问题