简体   繁体   English

如何向 angular 故事书添加指令

[英]How to add directives to angular storybook

I have a dropdown directive which I want to add to my storybook, its not working.我有一个下拉指令,我想将它添加到我的故事书中,但它不起作用。 When I run the button shows on the storybook but if I click on the button the template is not getting displayed.当我运行故事书上的按钮时,但如果我单击按钮,则不会显示模板。

import {moduleMetadata} from '@storybook/angular';
import {CommonModule} from '@angular/common';
import {DropdownModule} from '../../app/base-components/dropdown';

export default {
  title: 'dropdown',
  decorators: [
    moduleMetadata({
      declarations: [],
      imports: [CommonModule, DropdownModule]
    })
  ]
};

export const withDropdownTemplate = () => ({
  template: '<button dropDown></button>',
  props: {
    displayTpl: `<ng-template #dropdownTpl>
  <ul>
    Hello World
  </ul>
</ng-template>`
  }
});

I had the same question.我有同样的问题。

my solution: https://github.com/AnteaterCode/shatilokit/blob/master/src/stories/general/buttons.stories.ts我的解决方案: https://github.com/AnteaterCode/shatilokit/blob/master/src/stories/general/buttons.stories.ts

const modules = {
  imports: [
    ShButtonModule,
  ],
};

export default {
  title: 'general/Button',
  component: ShButton
} as Meta;


export const primary = () => ({
  moduleMetadata: modules,
  template: `
    <button shButton> Button </button>
  `,
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM