0

目前在使用 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

代码片段:

<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 { }

我在这里想念什么?

  • 有趣的注意事项:日期管道确实有效。
4

1 回答 1

2

没有index管道。您需要使用赋值语法并用分号分隔循环和赋值语句:

<li *ngFor="let s of grouplesson.start; let i = index">
于 2018-07-30T14:47:44.580 回答