Skip to content

help(ScrollingModule): Can't use Angular Material module in Storybook #23207

@AndrewAKovalenko

Description

@AndrewAKovalenko

What are you trying to do?

Add virtual scrolling component into my component library (Storybook)

What troubleshooting steps have you tried?

I tried complete removing of node_modules and reinstallation
Component is not present in Storybook, but if i try it in application itselt - it works fine
It appears both in View Engine and Ivy mode for my library

Reproduction

  1. Create component with ScrollingModule
  2. Create Storybook story with that component
  3. Observe console and component on canvas

ER: Component is present on canvas, no errors in console
AR: Canvas is empty, error in consol

Component template

<cdk-virtual-scroll-viewport
    [itemSize]="50"
    [style.height]="'200px'">
    <div *cdkVirtualFor="let item of [1,2,3,4,5,6,7,8,9]"
         [style.height]="'50px'">
        {{ item }}
    </div>
</cdk-virtual-scroll-viewport>

Module itself

@NgModule({
    declarations: [VirtualScrollComponent],
    imports: [
        CommonModule,
        ScrollingModule,
    ],
    exports: [VirtualScrollComponent],
})
export class VirtualScrollModule {
}

Storybook story

export default {
    title: 'Components/Virtual Scroll',
    decorators: [
        withKnobs,
        moduleMetadata({
            imports: [VirtualScrollModule],
        }),
    ],
};

export const Default = () => ({
    template: `
        <app-virtual-scroll
            [items]="items"
            [itemSize]="itemSize"
            [itemTemplate]="itemTemplate"
            [viewportHeight]="viewportHeight">
        </app-virtual-scroll>
    `,
    props: {
        itemSize: number('Item size', 50),
        viewportHeight: number('Viewport height', 300),
        items,
    },
});

image

Environment

  • Angular: 11.2.14
  • CDK/Material: 11.2.13
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions