如何将有角度的材质成分正确导入StoryBook CSF

时间:2019-10-22 03:46:44

标签: angular angular-material storybook angular-storybook

我有一个相对简单的角分量,它使用角材料分量-特别是mat-menu。

创建故事时,出现运行时错误:

    Error: Template parse errors:
Can't bind to 'matMenuTriggerFor' since it isn't a known property of 'button'. ("
        </li>
        <li class="nav-item">
          <button class="menubtn" mat-icon-button [ERROR ->][matMenuTriggerFor]="menu">
            <span class="fa-stack fa-md">
              <i class="fa fa-g"): ng:///DynamicModule/VeradigmHeaderComponent.html@33:50
There is no directive with "exportAs" set to "matMenu" ("
            </span>
          </button>
          <mat-menu [ERROR ->]#menu="matMenu" xPosition="before">
            <button mat-menu-item (click)="setLoc('en_US')">en-US"): ng:///DynamicModule/VeradigmHeaderComponent.html@38:20
'mat-menu' is not a known element:
1. If 'mat-menu' is an Angular component, then verify that it is part of this module.
2. If 'mat-menu' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
            </span>
          </button>

我假设我必须导入MatMenuModule,但是我不知道该怎么做。这是我的故事:

import {TestHeaderComponent} from './test-header.component';
import { MatMenuModule} from '@angular/material';


export default {
    title: 'Test Header',
};

export const TestHeader= () => ({
    component: TestHeaderComponent,
    props: { },
});

TestHeader.story = {
    name: 'default',
    imports: [
        MatMenuModule,
    ],
};

我也尝试将导入内容直接放在Testheader中,但是没有一个起作用。如果我使用storyOfOf API,则可以这样做:

stories.addDecorator(
    moduleMetadata({
        imports: [MatMenuModule],
    })
);

但是我不知道CSF中的格式。请帮忙!

1 个答案:

答案 0 :(得分:1)

我已经这样做了

import { moduleMetadata } from '@storybook/angular';

export default {
    title: "Task",
    decorators: [
        moduleMetadata({
            imports: [MyModule]
        })
    ]
}