gpt4 book ai didi

angular - 如何将 MatButton 添加到 Angular 库中(Angular 9)

转载 作者:行者123 更新时间:2023-12-03 20:10:51 25 4
gpt4 key购买 nike

关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。












想改进这个问题?将问题更新为 on-topic对于堆栈溢出。

2年前关闭。




Improve this question




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

ng g library multi-select



现在我想添加 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 { }

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

最佳答案

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

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

@NgModule({
// ...
imports: [ MatButtonModule ],
// ...
})
export class MultiSelectModule {}

关于angular - 如何将 MatButton 添加到 Angular 库中(Angular 9),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60130872/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com