angular - mat-button 不是已知元素

标签 angular angular-material

我不明白。我想我导入了所有必要的模块,但它一直告诉我:

'mat-button' is not a known element:

应用程序模块.ts:

import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { AppComponent } from './app.component';

@NgModule({
  imports: [
    BrowserModule,
    FormsModule,
    BrowserAnimationsModule,
    MatButtonModule,
  ],
  declarations: [AppComponent],
  providers: [],
  bootstrap: [AppComponent],
})
export class AppModule {}

应用程序组件.ts:

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss'],
})
export class AppComponent {
  constructor() {}
}

app.component.html

<mat-button>foo</mat-button>

app.component.scss 是空的。

我知道有很多关于此的帖子。但没有任何帮助,因为我认为我正确导入了所有内容 (MatButtonModule)。有人知道我能做什么吗?

最佳答案

它是:

<button mat-button>foo</button>

不是

<mat-button>foo</mat-button>

Official doc.

关于angular - mat-button 不是已知元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53671845/

相关文章:

javascript - 如何在 <md-radio-group> 中使用输入字段作为自定义条目?

css - Angular Material 在中间制作水平线的方式

angular - 如何在 MatDialog 中使用 scrollStrategy?

twitter-bootstrap - Angular 2 Material : same height for MdCards

Angular 与 Dart

javascript - md-autocomplete 未显示

node.js - 错误TypeError : Cannot read property 'BrowserWindow' of undefined in angular version 10 and electron version 10 and ngx-electron 2. 2.0

javascript - Angular 的 HashId

angular - 如何在库项目中具有绝对导入路径?

Angular 2 Cli 向现有项目添加路由