4

我使用命令在一个新的 angular 9 项目上生成了一个库

ng g 库多选

现在我想添加 Angular Material 的 MatButton,所以我在库的主模块中添加了“MatButtonModule”。我还在库的 package.json 中添加了 "@angular/material": "^9.0.0" 作为依赖项,并将其列入了 ng-package.json 的白名单。当我尝试构建库时(ng build multi-select)它说

Compiling TypeScript sources through ngc
ERROR: node_modules/@angular/material/button/button.d.ts:22:22 - error NG6002: Appears in the NgModule.imports of MultiSelectModule, but could not be resolved to an NgModule class

22 export declare class MatButton extends _MatButtonMixinBase implements OnDestroy, CanDisable, CanColor, CanDisableRipple, FocusableOption {
                        ~~~~~~~~~
node_modules/@angular/material/button/button.d.ts:22:22 - error NG6003: Appears in the NgModule.exports of MultiSelectModule, but could not be resolved to an NgModule, Component, Directive, or Pipe class

22 export declare class MatButton extends _MatButtonMixinBase implements OnDestroy, CanDisable, CanColor, CanDisableRipple, FocusableOption {
                        ~~~~~~~~~

An unhandled exception occurred: node_modules/@angular/material/button/button.d.ts:22:22 - error NG6002: Appears in the NgModule.imports of MultiSelectModule, but could not be resolved to an NgModule class

22 export declare class MatButton extends _MatButtonMixinBase implements OnDestroy, CanDisable, CanColor, CanDisableRipple, FocusableOption {
                        ~~~~~~~~~
node_modules/@angular/material/button/button.d.ts:22:22 - error NG6003: Appears in the NgModule.exports of MultiSelectModule, but could not be resolved to an NgModule, Component, Directive, or Pipe class

22 export declare class MatButton extends _MatButtonMixinBase implements OnDestroy, CanDisable, CanColor, CanDisableRipple, FocusableOption {

这就是多选模块的外观

import { NgModule } from '@angular/core';
import { MultiSelectComponent } from './multi-select.component';
import { MatButton } from '@angular/material/button';
import { FormsModule  } from '@angular/forms';
import { SearchPipe } from './search.pipe';

@NgModule({
      declarations: [MultiSelectComponent, SearchPipe],
      imports: [
        MatButton,
        FormsModule
      ],
      exports: []
    })
 export class MultiSelectModule { }

不用说,如果没有这个模块,库就可以很好地构建。这似乎是什么问题?

4

1 回答 1

9

在 的模块中MultiSelectModule,您正在导入MatButton. 您应该导入它的模块,MatButtonModule.

import { NgModule } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';

@NgModule({
  // ...
  imports: [ MatButtonModule ],
  // ...
})
export class MultiSelectModule {}
于 2020-02-08T20:36:20.563 回答