我在使用對象爲管* ngFor,當我在我的組件聲明管 - 我得到這個錯誤(VS代碼) - >管誤差ngFor在對象
[ts] Argument of type '{ selector: string; templateUrl: string; pipes: typeof ObjNgFor[]; providers: typeof TableCompone...' is not assignable to parameter of type 'ComponentMetadataType'.
Object literal may only specify known properties, and 'pipes' does not exist in type 'ComponentMetadataType'
這是我的組件:
import { Component, OnInit, Pipe, PipeTransform } from '@angular/core';
@Pipe({ name: 'ObjNgFor', pure: false })
export class ObjNgFor implements PipeTransform {
transform(value: any, args: any[] = null): any {
return Object.keys(value).map(key => Object.assign({ key }, value[key]));
}
}
@Component({
selector: 'tablecomponent',
templateUrl: 'app/table.template.html',
pipes: [ObjNgFor],
providers: [TableComponentService]
})
export class TableComponent implements OnInit {
lists: any;
constructor(public _service: TableComponentService) {
}
ngOnInit() {
this._service.getServices()
.subscribe(lists => this.lists = lists)
}
}
,這是我的模板與*ngFor
direcrive部分:
<tr *ngFor="let list of lists | ObjNgFor">
<td>{{ list.name}}</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
你可以有一個管道名稱與類名稱不完全相同嗎? –
@Harry Ninh你的意思是重命名管道或類?它不仍然工作 –