【发布时间】:2019-01-06 20:35:35
【问题描述】:
目前在使用 Angular 6 时,当我尝试将索引管道用于 NgFor 时出现以下错误:
Uncaught Error: Template parse errors:
The pipe 'index' could not be found ("
<ul class="list-unstyled"> <li *ngFor="l[ERROR ->]et s of grouplesson.start | index as i">
<span cl"): ng:///ModalModule/GrouplessonsComponent.html@80:61
代码sn-p:
<li *ngFor="let s of grouplesson.start | index as i">
<span class="time__start">{{s | date:'HH:mm'}}</span>
<span> - </span>
<span class="time__end">{{grouplesson.end[i] | date:'HH:mm'}}</span>
</li>
我觉得这很奇怪,因为在不使用管道时循环确实可以工作,而且据我所知,我还正确地导入了 ModalModule 中的 commonmodule:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ModalComponent } from './modal.component';
import { ModalService } from './services/modal.service';
import { GrouplessonsComponent } from './components/grouplessons/grouplessons.component';
@NgModule({
imports: [
CommonModule
],
declarations: [ModalComponent, GrouplessonsComponent],
providers: [ModalService],
exports: [ModalComponent, GrouplessonsComponent]
})
export class ModalModule { }
我在这里错过了什么?
- 有趣的提示:日期管道确实工作。
【问题讨论】:
-
如果你想访问索引
let i = index,你应该使用assign语句
标签: angular angular6 angular-pipe angular2-pipe angular-ngfor