typescript 带故事书的独立角管:NG0302:在零部件中找不到管道

wn9m85ua  于 2023-02-14  发布在  TypeScript
关注(0)|答案(1)|浏览(106)

得到了在Storybook中包含一个独立管道的任务。我的管道简单如:从“@angular/core”导入{管道,管道变换};

@Pipe({
    name: 'shortpipe',
    standalone: true,
})
export class ShortPipe implements PipeTransform {
    transform(value: any): any {
        return 'hello';
    }
}

即使我的故事书故事也没有那么复杂:

const meta: Meta<any> = {
    title: 'Title of my fantastic story',
    render: () => ({
        template: `<p>{{'22222' | shortpipe}}</p>`,
    }),
};

export default meta;
type Story = StoryObj<any>;

export const Default: Story = {
    render: (args) => ({
        moduleMetadata: [
            {
                imports: [ShortPipe],
            },
        ],
        template: `<p>{{'22222' | shortpipe}}</p>`,
    }),
};

然而,我得到了错误:NG0302: The pipe 'shortpipe' could not be found in the 'StorybookWrapperComponent' component. Verify that it is declared or imported in this module. Find more at https://angular.io/errors/NG0302
Angular :15.0.2
@故事书/棱角:6.5.15

x8diyxa7

x8diyxa71#

已经找到了答案,问题只是把moduleMetadata导入放到了错误的位置。把它移到装饰器数组中修复了它:

export const Default: Story = {
   decorators: [
       moduleMetadata({
           imports: [ShortPipe],
       }),
   ],
   render: (args) => ({
       template: `<p>{{'22222' | shortpipe}}</p>`,
   }),
};

相关问题