New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Angular: ngModel/ngModelChange don't work in Storybook 6.2+ #14643
Comments
@daan93 Looks like you need to explicitly import FormsModule into your story. Do you have something like this in your code?
|
@vetrov I did not have the decorator in my stories, thanks for pointing that out. When I add it, including the required imports, the story will render and the controls will work. Previously I did not need the decorator, I guess I will update my stories now. Would be nice to have some documentation on this. Required imports:
|
@ThibaudAV any idea what's changed? ☝️ |
🤔 arf, Bad behaviors of previous version which gives bad habits, I think 😁. The FormsModule was always loaded by storybook probably for some obscure reason. As the new renderer behaves like a real angular application in this case if. So there are the same errors as if you have an angular application without this import the error message of angular is ~clear. But maybe a precision can be brought in the MIGRATION.md or the answer to this issue is enough 🤷♂️ |
@ThibaudAV how about the original question, have you noticed this issue with Storybook 6.2+? |
@vetrov Could you provide an example where it does not work from this story 🙏 ? The new renderer generates a "template" so if the component is placed in the same condition (import, dep,...) as an angular application. there should be no difference 🤔 |
@ThibaudAV, sure, here is how to reproduce what I'm doing: Open Storybook example for Angular form control: open story. It is based on v6.3.0-alpha.16 as I can see from About. As I understood this is a source code for the example above: source code Looking on source code I expect, that:
Same behaviour I observe when running the same example story for Storybook 6.2.9 Here is the same story for Storybook 6.1.21 and it works as expected: https://storybookjs.netlify.app/angular-cli/?path=/story/custom-ngmodel--custom-control-value-accessor |
I find that if you set a props in story, let's say 'A'. Story will only set it on the Component when the Component does have an @input var named A. If not, story won't set 'A' prop. So I guess this issue is caused because custom form control component actually doesn't need us to set ngModel & ngModelChange as @input or @output vars. And story doesn't set ngModel prop when render the Component. And angular form module won't activate form control system on the Component. And writeValue method never be called. |
Reproduced using SB 6.5.16. Any news? |
Please try upgrading to the latest prerelease. Is it still a problem? Migration guide: https://storybook.js.org/migration-guides/7.0 |
Hi, any update on this? I've upgraded to version 7 of Storybook and it's still an issue. It appears after looking at the new code that the ngModel and ngChangeModel values are no longer set from the properties values like they were in version 6.1. |
Hello, same problem here, any updates how to fix this updating ngModel? I feel like storybook 7.4 + angular 15 is a little messy in few points. |
What's the problem?
There was a way to define inputs for Angular components implementing ControlValueAccessor interface (reactive form controls) by using
ngModel
andngModelChange
as props in story. After upgrading to Storybook 6.2 these props seems do not work anymore.TypeError: instance.writeValue is not a function
, value is not passed to the componentExample:
Story for this use case exists in the demo, but does not work as well: https://next--storybookjs.netlify.app/angular-cli/?path=/story/basics-angular-forms-controlvalueaccessor--simple-input (currently works on Storybook 6.3.0-alpha.9)
Code for this story: https://github.com/storybookjs/storybook/blob/v6.3.0-alpha.9/examples/angular-cli/src/stories/basics/angular-forms/customControlValueAccessor/custom-cva-component.stories.ts
Is there documentation on this?
ngModel
andngModelChange
are not mentioned in documentation, so it's more like undocumented (but implemented) feature.Here is more details on how it is implemented in old renderer: https://github.com/storybookjs/storybook/blob/v6.2.8/app/angular/src/client/preview/angular/components/app.component.ts#L110
Additional context
Would be good to understand if it's a bug or there's now another way to create stories for Angular form controls.
The text was updated successfully, but these errors were encountered: