【问题标题】:Angular 6 The pipe 'index' could not be foundAngular 6找不到管道“索引”
【发布时间】: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


【解决方案1】:

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

<li *ngFor="let s of grouplesson.start; let i = index">

【讨论】:

  • 啊,是的。由于那里的异步管道,我似乎误读了文档。干杯!
猜你喜欢
  • 2021-05-28
  • 2019-04-29
  • 1970-01-01
  • 1970-01-01
  • 2019-04-23
  • 1970-01-01
  • 2017-12-08
  • 2017-03-25
  • 2020-09-21
相关资源
最近更新 更多