I am currently working on setting up Storybook 8.0.8 with Angular 17.3. I have been using the Angular input()
signal in my components, but I've encountered an interesting issue where the args for the storybook stories also need the argument type to be a signal. Trying to access the injection context in the story doesn't seem like the ideal solution to me.
I am looking for a cleaner way to provide my args as literal values, as it used to be. Has anyone faced this problem before and discovered a good workaround?
Below is a basic angular component and storybook story that demonstrates the issue:
const meta: Meta<NoteComponent> = {
title: 'Shared/Note',
component: NoteComponent,
tags: ['autodocs'],
args: {
maxChars: 200 // Error: Type 'number' is not assignable to type 'InputSignal<number>'.
}
};
export default meta;
type Story = StoryObj<NoteComponent>;
export const Primary: Story = {
};
@Component({
selector: 'app-note',
template: 'A note with {{maxChars()}} maximum characters',
standalone: true,
})
export class NoteComponent {
maxChars = input<number>(300);
}
Just a reminder, when using any signal()
creation function, make sure there is an injection context available. Using signal()
without an injection context will result in
NG0203: inputFunction() can only be used within an injection context such as a constructor, a factory function, a field initializer, or a function used with runInInjectionContext