代码之家  ›  专栏  ›  技术社区  ›  Luk

不在Firefox中工作时对ngf中enum的迭代

  •  0
  • Luk  · 技术社区  · 7 年前

    我已经创建了一个select元素,在其中我创建了选项:

       <mat-option
            [value]="ift"
            *ngFor='let ift  of inputFileTypes | elements'>
            {{ "generator.inputFileType." + ift | translate}}
        </mat-option>
    

    其中我使用管道获取枚举的所有元素

    import {Pipe, PipeTransform} from '@angular/core';
    
    @Pipe({
        name: 'elements'
    })
    export class EnumElementsPipe implements PipeTransform {
        transform(data: Object) {
          return Object.keys(data);
        }
    }
    

    inputFileTypes是一个枚举(在组件.ts: inputFileTypes = InputFileType )

    export enum InputFileType {
        TYPE1= 'TYPE1',
        TYPE2= 'TYPE2'
    }
    

    这在Chrome和Opera中创建了我的select选项,但在Firefox上不起作用。没有错误,但不会创建选项。知道为什么吗?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Jota.Toledo    7 年前

    如果您使用的是angular>=6.1.x的版本,则可以通过使用 KeyValuePipe 具体如下:

    <mat-option
            [value]="ift"
            *ngFor='let ift  of inputFileTypes | keyvalue'>
            {{ "generator.inputFileType." + ift.key| translate}}
        </mat-option>
    

    the following stackblitz

    推荐文章