12

I have a relatively simple angular component that uses angular material components - mat-menu in particular.

When I create my story, I get a runtime error:

    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>

I assume I have to import the MatMenuModule, but I cannot figure out how to do this. Here is my story:

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,
    ],
};

I tried putting the imports in Testheader directly as well but neither one works. If I use the storiesOf API, I can do it like this:

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

But I don't know the format in CSF. Please help!

Dave Vronay
  • 625
  • 7
  • 22
  • Did you import MatMenuModule in your app.module.ts ? – Yvan Oct 22 '19 at 04:14
  • It is in the my app module. I can make it work with the storiesOf format using stories.addDecorator(moduleMetadata({imports: [MatMenuModule]})) but I don't know how to do it in CSF. – Dave Vronay Oct 23 '19 at 13:11

1 Answers1

21

I've done it like this

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

export default {
    title: "Task",
    decorators: [
        moduleMetadata({
            imports: [MyModule]
        })
    ]
}
Lyle Balcom
  • 226
  • 2
  • 4