0

Github:https ://github.com/danielhdz56/storybook-demo.git

在组件中注入服务总是会在故事书中引发错误:

Error: Can't resolve all parameters for CustomService: (?).

一个示例组件:

 @Component({
   selector: 'app-custom-selector',
   templateUrl: './custom-selector.component.html',
   styleUrls: ['./custom-selector.component.scss'],
 })
 export class NavigationItemComponent {
   constructor(private customService: CustomService) {}
 }
4

1 回答 1

2

哟需要将它们添加到模块元数据中

const modules = {
    imports: [..],
    providers: [CustomService],
    declarations: [NavigationItemComponent ]
};

// Then in stories: 
.add('description',
    () => ({
        component: NavigationItemComponent ,
        props: {...},
        moduleMetadata: modules
    }
)
于 2019-10-31T16:35:59.083 回答