我在使用对象为管* 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你的意思是重命名管道或类?它不仍然工作 –