angular - Angular Library : Material Menu : Error: Export of name 'matMenu' not found
问题描述
I'm working on an Angular Library, I have this simple menu :
<mat-menu #menu="matMenu" yPosition="below" style="margin-top: 45px;">
<button style="outline: none;" *ngFor='let button of card?.overflowmenu?.buttons' mat-menu-item
class="header-menu-item">
{{button.text}}
</button>
</mat-menu>
And the module looks like this.
import { NgModule } from '@angular/core';
import { CardComponent } from './card.component';
import { MatMenuModule } from '@angular/material/menu';
import { CommonModule } from '@angular/common';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { BrowserModule } from '@angular/platform-browser';
@NgModule({
declarations: [CardComponent],
imports: [
BrowserModule,
CommonModule,
BrowserAnimationsModule,
MatMenuModule,
],
exports: []
})
export class CardModule { }
When I do : $ng test @libraryname.
I get the error: Error: Export of name 'matMenu' not found!
Is there something I'm missing to import when building an Angular library?
解决方案
您的测试也需要导入模块 - 所以您需要
import { MatMenuModule } from '@angular/material/menu';
在您的 .spec.ts 文件的导入中,然后
TestBed.configureTestingModule({
declarations: [YourComponent],
imports: [
NoopAnimationsModule,
LayoutModule,
...
MatMenuModule,
]
}).compileComponents();
在你的测试文件中
推荐阅读
- bash - 如何检查 .sql 脚本执行是否成功?
- java - 模拟 DateFormat、SimpleDateFormat、Date 类
- flutter - 将值从 android 传递到颤振,但不是从主要活动
- python - Python 数组 3D 转视频
- powershell - Export-Csv 等价于 Write-Output
- javascript - javascript中的自制文本转语音无法正常工作
- python - tslearn.clustering.TimeSeriesKMeans 与 sklearn.cluster.KMeans
- excel - 表格单元格中的 Word VBA 格式编号 - 单元格文本无法识别
- r - 使用 R 中的行名创建公式
- c# - 如何根据条件告诉 JsonWriter 什么都不做?