【发布时间】:2017-10-05 12:41:52
【问题描述】:
我正在尝试在 Angular 4 上使用管道进行排序。管道和 ngFor 没有问题。
<div *ngFor="let item of data | paginate: { itemsPerPage: 8, currentPage: p } | orderBy : ['{{config}}'] " class="col-lg-3 col-md-6 col-sm-6">
<blog-thumb [date]="item.date" [commentCount]="item.commentCount"> </blog-thumb>
</div>
像上面一样,有 2 个我自己开发的管道。使用该语法存在错误。换成这个就没有问题了
这是我的组件类。
export class MainBlogPageComponent implements OnInit {
public sortOrder: string = "asc";
public config: string = "-commentCount";
private data: any;
private blogPosts: string;
constructor() {
}
ngOnInit() { }
}
还有我所有的模块CommonModule 导入,BrowserModule App.Module.ts 也导入了
这是在 chrome 浏览器上看到的异常。
Can't bind to '*ngFor' since it isn't a known property of 'div'. ("
</div>
</div>
<div [ERROR ->]*ngFor="let item of data | paginate: { itemsPerPage: 8, currentPage: p } | orderBy : ['{{config}}'] "): ng:///MainBlogModule/MainBlogPageComponent.html@37:13
Error: Template parse errors:
Can't bind to '*ngFor' since it isn't a known property of 'div'. ("
</div>
</div>
<div [ERROR ->]*ngFor="let item of data | paginate: { itemsPerPage: 8, currentPage: p } | orderBy : ['{{config}}'] "):
它不像模板解析错误等其他异常。没看懂问题出在哪里。
这是MainBlogPageComponent 导入的我的模块。
@NgModule({
imports: [CommonModule,
FormsModule,
NgaModule,
routing,
NgxPaginationModule
],
exports: [],
declarations: [MainBlogComponent,
MainBlogPageComponent,
SubHeaderComponent,
BlogThumbComponent],
providers: [],
})
export class MainBlogModule { }
我的共享模块中的管道,我所有的管道都位于共享模块和共享模块中。我使用了另一个没有问题的模块。
【问题讨论】:
-
可以在定义
MainBlogPageComponent的地方添加@NgModule配置吗? -
已更新,希望一切正常。谢谢。
-
尝试从
ngFor移除管道 -
正如我在问题上所说的那样,当我更改为像“+commentCount”这样的静态参数时,它就好了。我只想使用参数。
标签: angular angular2-directives angular2-pipe