angular - ViewChild 如何在 Angular 和 Storybook 中工作?
问题描述
我有一个名为 inline-help 的组件。组件的模板是这样的:
<div class="inline-help" #helpBlock>
<div class="help-icon" (mouseover)="handleMouseOver($event)" (mouseout)="handleMouseOut()">
<i class="icon-help"></i>
</div>
<div #helptext class="inline-help-text text-left" [class.inline-help-visible]="visible">
<ng-content select="help-title" class="help-title"></ng-content>
<ng-content select="help-body" class="help-body"></ng-content>
</div>
</div>
这个组件可以像这样使用(并且正常工作):
<inline-help>
<help-title>This is the title</help-title>
<help-body>This is the body</help-body>
</inline-help>
但是,这在文件中不起作用InlineHelp.stories.ts
:
export default {
title: 'Library/Inline-help',
component: InlineHelpComponent,
decorators: [
moduleMetadata({
declarations: [InlineHelpComponent],
imports: [CommonModule],
}),
],
} as Meta;
const Template: Story<InlineHelpComponent> = (args: InlineHelpComponent) => ({
component: InlineHelpComponent,
props: args,
template: `
<inline-help>
<help-title>my title</help-title>
<help-body>my help body</help-body>
<inline-help>
`,
});
export const InlineHelp = Template.bind({});
我收到此错误:
Template parse errors:
'help-title' is not a known element:
1. If 'help-title' is an Angular component, then verify that it is part of this module.
2. If 'help-title' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
我不确定要在这里做什么来呈现传入的内容。
解决方案
You have to include all the components that you are using in your story under the declarations
in the moduleMetadata
section of your story.
This could look like this:
export default {
title: 'Library/Inline-help',
component: InlineHelpComponent,
decorators: [
moduleMetadata({
declarations: [InlineHelpComponent, HelpTitleComponent, HelpBodyComponent],
imports: [CommonModule],
}),
],
} as Meta;
(This assumes the component names for help-title and help-body are HelpTitleComponent
and HelpBodyComponent
)
推荐阅读
- node.js - 使用新的节点快速服务器连接到现有 MongoDB
- c# - 如何以打开文件对话框样式选择正在运行的进程?
- kubernetes - 给定一些 kubernetes 模板,如何获取 docker 镜像列表?
- sql-server - ASP.Net MVC - 插入和更新
- java - Postgres 错误:门户“C_n”不存在
- javascript - Changing VS code style
- javascript - 如何将变量“if”应用于第 9 行
- reactjs - django和react的常用文件夹设计
- ruby-on-rails - 为什么我不能下载rails?
- java - 保险柜加载太晚