简体   繁体   English

由模块'AppModule'导入的意外指令'MatSpinner'。 请添加@NgModule注释

[英]Unexpected directive 'MatSpinner' imported by the module 'AppModule'. Please add a @NgModule annotation

Angular 5 - 角5 -

here are the npm modules (package.json)- 这是npm模块(package.json) -

   "@angular/animations": "^5.0.0",
    "@angular/cdk": "^5.0.0-rc.2",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/material": "^5.0.0-rc.2",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/router": "^5.0.0",
    "core-js": "^2.4.1",
    "hammerjs": "^2.0.8",
    "rxjs": "^5.5.2",
    "zone.js": "^0.8.14"

I am using Angular material Spinner as MatSpinner Directive from Material module 我使用Angular材质Spinner作为Material模块的MatSpinner指令

import { MatSpinner } from "@angular/material";
@NgModule({
imports: [

MatSpinner
],
declarations: [],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }

Here is the HTML: 这是HTML:

<mat-spinner></mat-spinner>

I am Getting an ERROR- 我得到一个错误 -

Unexpected directive 'MatSpinner' imported by the module 'AppModule'. 由模块'AppModule'导入的意外指令'MatSpinner'。 Please add a @NgModule annotation. 请添加@NgModule注释。

In your app-module, you would generally import MatProgressSpinnerModule, not MatSpinner. 在你的app-module中,你通常会导入MatProgressSpinnerModule,而不是MatSpinner。 MatSpinner would be imported in your component. MatSpinner将导入您的组件中。

MatSpinner & MatProgressSpinner are component and already part of MatProgressSpinnerModule . MatSpinner和MatProgressSpinner是组件,已经是MatProgressSpinnerModule的一部分。

In Angular, 在Angular,

  • A component can not be added in imports of @NgModule @NgModule的 导入中无法添加组件
  • A component can not be part of declarations of more than one @NgModule 组件不能是多个@NgModule声明的一部分

As both the components are available in MatProgressSpinnerModule , you should add MatProgressSpinnerModule in imports of your @NgModule . 由于这两个组件都在MatProgressSpinnerModule中可用, 因此您应该在@NgModule导入中添加MatProgressSpinnerModule

Example

import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';

@NgModule({
  imports: [
    MatProgressSpinnerModule
  ],
  declarations: [],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 由模块&#39;AppModule&#39;导入的意外指令&#39;LoginPage&#39;。 请添加@NgModule注释 - Unexpected directive 'LoginPage' imported by the module 'AppModule'. Please add a @NgModule annotation 由模块'AppModule'导入的意外指令'LoginComponent'。请添加@NgModule注释 - Unexpected directive 'LoginComponent' imported by the module 'AppModule'. Please add a @NgModule annotation 模块“AppModule”导入的意外指令“MatAutoCompleteTrigger”。 请添加@NgModule 注释 - Unexpected directive 'MatAutoCompleteTrigger' imported by the module 'AppModule'. Please add a @NgModule annotation 模块“AppModule”导入的意外值“MatSnackBar”。 请添加@NgModule 注解 - Unexpected value 'MatSnackBar' imported by the module 'AppModule'. Please add a @NgModule annotation 模块&#39;AppModule&#39;导入的意外值&#39;MDCTextField&#39;。 请添加@NgModule注释 - Unexpected value 'MDCTextField' imported by the module 'AppModule'. Please add a @NgModule annotation 模块'AppModule'导入的意外值'DataTablesModule'。请添加@NgModule注释 - Unexpected value 'DataTablesModule' imported by the module 'AppModule'. Please add a @NgModule annotation 模块“ AppModule”导入的异常值“ AngularFireDatabase”。 请添加@NgModule批注 - Unexpected value 'AngularFireDatabase' imported by the module 'AppModule'. Please add a @NgModule annotation 模块“ AppModule”导入了意外值“ Validators”。 请添加@NgModule批注 - Unexpected value 'Validators' imported by the module 'AppModule'. Please add a @NgModule annotation 由模块“AppModule”导入的意外值“FormBuilder”。 请添加@NgModule 注释 - Unexpected value 'FormBuilder' imported by the module 'AppModule'. Please add a @NgModule annotation 模块&#39;AppModule&#39;导入了意外的值&#39;MatMenu&#39;。 请添加@NgModule批注 - Unexpected value 'MatMenu' imported by the module 'AppModule'. Please add a @NgModule annotation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM