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) {}
}
答案 0 :(得分:0)
您需要将它们添加到metaData模块中
const modules = {
imports: [..],
providers: [CustomService],
declarations: [NavigationItemComponent ]
};
// Then in stories:
.add('description',
() => ({
component: NavigationItemComponent ,
props: {...},
moduleMetadata: modules
}
)