模板解析错误:没有带有“exportAs"的指令;设置为“matMenu" [英] Template parse errors: There is no directive with "exportAs" set to "matMenu"

查看:20
本文介绍了模板解析错误:没有带有“exportAs"的指令;设置为“matMenu"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着 Angular Material 及其 重大更改,我无法再使用我的 组件.当我导入 MaterialModule 时它正在工作,但现在导入 MatMenuModule 或 MdMenuModule 时生成以下错误:

With the new update of Angular Material and its breaking changes, I can no longer use my <md-menu> components. It was working when I imported MaterialModule, but now when importing MatMenuModule or MdMenuModule the following error is generated:

compiler.es5.js:1690 Uncaught Error: Template parse errors:
There is no directive with "exportAs" set to "matMenu" ("
</mat-toolbar>
  <mat-menu xPosition="after" [ERROR ->]#wordListMenu="matMenu" 
): 
ng:///NavbarModule/NavbarComponent.html@38:28

我遵循文档中的指南和API,但语法似乎有变了?我已经尝试了 #wordListMenu="matMenu"#wordListMenu="mdMenu" 并且错误仍然存​​在.

I follow the guide and API at the documentation, but the syntax seems to have changed? I've tried both #wordListMenu="matMenu"and #wordListMenu="mdMenu" and the error persist.

我的 html 文件(相关部分)是:

My html file (relevant parts) is :

<button mat-button [md-menu-trigger-for]="wordListMenu" [ngClass]="{'active' 
  : isActive(['/wordlist'])}">
  Word Lists
</button>
<mat-menu xPosition="after" #wordListMenu="matMenu" 
  [overlapTrigger]="false">
  //Content of menu
</mat-menu>

我的模块是:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import {NavbarComponent} from 'app/navbar/navbar.component';
import { MdTooltipModule, MatMenuModule } from '@angular/material';

@NgModule({
  imports: [
    CommonModule,
    MdTooltipModule,
    MatMenuModule
  ],
  declarations: [NavbarComponent],
  exports: [NavbarComponent]
})
export class NavbarModule { }

有什么我遗漏的吗?为什么编译器不识别 matMenu?

Is there something I am missing? Why doesn't the compiler recognize matMenu?

推荐答案

问题在于您的 Angular 版本.将您的 angular 版本更新到 4.4.3 或更高版本.材料 2.0.0-beta.11 取决于 4.4.3 或更高版本.来自 变更日志 文档:

The problem is with your angular version. Update your angular version to 4.4.3 or greater. Material 2.0.0-beta.11 depends on 4.4.3 or greater. From the CHANGELOG documentation:

重大变化Angular Material 现在需要 Angular 4.4.3 或更高版本

Breaking changes Angular Material now requires Angular 4.4.3 or greater

链接到 工作演示.

这篇关于模板解析错误:没有带有“exportAs"的指令;设置为“matMenu"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆