当前使用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:
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 { }
我在这里想念什么?
答案 0 :(得分:2)
没有index
管道。您需要使用赋值语法,并使用分号分隔循环和赋值语句:
<li *ngFor="let s of grouplesson.start; let i = index">