简体   繁体   English

在 Storybook/angular 中导入 @ng-select/ng-select

[英]Importing @ng-select/ng-select in Storybook/angular

I'm trying to use @ng-select/ng-select in the storybook but it fails (MatIconModule works as expected).我正在尝试在故事书中使用@ng-select/ng-select,但它失败了(MatIconModule 按预期工作)。

import { NgSelectModule } from '@ng-select/ng-select';
import { MatIconModule } from '@angular/material/icon';

export default {
   title: 'shared/rating-stars',
   component: RatingStarsComponent,
   imports: [NgSelectModule, MatIconModule]
} as Meta;

The error message is standard: "core.js:14937 'ng-select' is not a known element: ..." so it looks like that NgSelectModule does not define components properly.错误消息是标准的:“core.js:14937 'ng-select' 不是已知元素:...”所以看起来 NgSelectModule 没有正确定义组件。 So I wanted to take a look at the module but I found out that node_modules/@ng-select/ng-select/lib/ng-select.module.d.ts almost empty (reinstallation of package do not help and I can reproduce it on both win/linux):所以我想看看这个模块,但我发现 node_modules/@ng-select/ng-select/lib/ng-select.module.d.ts 几乎是空的(重新安装 package 没有帮助,我可以重现它在win / linux上):

export declare class NgSelectModule {
}

Application itself is working correctly, any idea what could be wrong?应用程序本身工作正常,知道可能出了什么问题吗? Thanks a lot.非常感谢。

You may not require to import NgSelectModule in your component.您可能不需要在组件中导入 NgSelectModule。 Instead import it in your parent module.ts like this.而是像这样将其导入您的父 module.ts 中。 Then you can use it in your html file.然后您可以在 html 文件中使用它。

import { NgSelectModule } from '@ng-select/ng-select';
@NgModule({
  imports: [
    .....
    NgSelectModule,
    .....
  ],
  declarations: []
})
export class MyModule { }

See the documentation for decorators and tutorial for composite component .请参阅装饰器的文档和复合组件的教程。 Need to add it as moduleMetadata to the component decorators.需要将其作为 moduleMetadata 添加到组件装饰器中。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM