我有一个 Select 可以控制一个似乎不起作用的列表.我在控制台中得到的错误是 core.mjs:6531错误错误:NG 05105:发现意外的合成监听器@transformPanel.done.请确保:

  • BrowserAnimationsModuleNoopAnimationsModule将导入您的应用程序中.

Typescript :

import { Component } from '@angular/core';
import { MatDividerModule } from '@angular/material/divider';
import { MatIconModule } from '@angular/material/icon';
import { DatePipe } from '@angular/common';
import { MatListModule } from '@angular/material/list';
import { MatSelectModule } from '@angular/material/select';
import { MatTooltipModule } from '@angular/material/tooltip';
import { provideAnimations } from '@angular/platform-browser/animations'; 
import { MatFormFieldModule } from '@angular/material/form-field';
import { FormsModule } from '@angular/forms';

export interface legend {
  name: string;
  image: string;
  tooltip: string;
}
export interface maplist {
  name: string;
  legends: Array<legend>
}



@Component({
  selector: 'app-legend',
  standalone: true,
  imports: [MatListModule, MatIconModule, MatDividerModule, DatePipe,
    MatSelectModule, MatTooltipModule, MatFormFieldModule, FormsModule, 
  ],
  providers: [
    provideAnimations()
  ],
  templateUrl: './legend.component.html',
  styleUrl: './legend.component.css',
})
export class LegendComponent {
  selectedValue: Array<legend> = [];

  maplistdata: maplist[] = [
    {
      name: "Echocondria",
      legends: [
        {
          name: "House",
          image: "",
          tooltip: "Living quarters for the residents."
        },
        {
          name: "Shop",
          image: "",
          tooltip: "Places to buy and sell goods."
        },
      ]
    },
    {
      name: "Echocondria Sewers",
      legends: [
        {
          name: "House",
          image: "",
          tooltip: "Living quarters for the residents."
        },
        {
          name: "Shop",
          image: "",
          tooltip: "Places to buy and sell goods."
        },
      ]
    },
  ]
}

Html:

  <mat-form-field>
  <mat-label>Select an option</mat-label>
  <mat-select 
    color="primary"
    [(ngModel)]="selectedValue" name="legendselect"
  >
    <mat-option>None</mat-option>
    @for (legend of maplistdata; track legend) {
        <mat-option [value]="legend.legends">{{legend.name}}</mat-option>
    }
   </mat-select>
  </mat-form-field>

  @for (legenditem of selectedValue; track legenditem) {
  <mat-list-item>
  <mat-icon matListItemIcon>folder</mat-icon>
  <div matListItemTitle [matTooltip]="legenditem.tooltip"><img class="legendIcon" [src]="legenditem.image"/> {{ legenditem.name }}</div>
   <div matListItemLine>{{legenditem.tooltip}}</div>
</mat-list-item>
  }

我try 导入有问题的模块,但仍然得到相同的错误或模块已包含的错误.

推荐答案

provideAnimations()所属的Provider 是您应用程序的根.无论是在配置boostrapApplication中,或者如果您依赖于AppMode,您都应该导入BrowserAnimationModule.

Typescript相关问答推荐

TS 2339:属性切片不存在于类型DeliverableSignal产品[]上>'

如何在ts中使用函数重载推断参数类型

打印脚本丢失函数的泛型上下文

更新为Angular 17后的可选链运算符&?&问题

泛型类型联合将参数转换为Never

当方法参数和返回类型不相互扩展时如何从类型脚本中的子类推断类型

如何在编译时为不带常量的参数引发错误

是否存在类型联合的替代方案,其中包括仅在某些替代方案中存在的可选属性?

已解决:如何使用值类型限制泛型键?

使用2个派生类作为WeakMap的键

不带其他属性的精确函数返回类型

常量类型参数回退类型

APP_INITIALIZER在继续到其他Provider 之前未解析promise

无法将从服务器接收的JSON对象转换为所需的类型,因此可以分析数据

当数组类型被扩展并提供标准数组时,TypeScrip不会抱怨

从以下内容之一提取属性类型

带有';的类型脚本嵌套对象可选属性错误满足';

为什么过滤器不改变可能的类型?

将对象数组传递给 Typescript 中的导入函数

如何强制对象数组中的对象属性具有非空字符串值?