question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Knobs with angular component not updating

See original GitHub issue

Describe the bug When using props on a component, the values of the knobs are not available in the component.

To Reproduce See code snippet

Expected behavior I expect the value within the component to be updated when I type in the text knob

Screenshots If applicable, add screenshots to help explain your problem.

Code snippets

import {storiesOf, moduleMetadata} from '@storybook/angular';
import {Component, Input} from '@angular/core';
import {withKnobs, text} from '@storybook/addon-knobs';
import {FormsModule} from '@angular/forms';

@Component({
  selector: 'simple-component',
  template: `
    {{ name || 'default' }}
    <input type="text" [(ngModel)]="name" />
  `,
})
export class SimpleComponent {
  @Input() name: string;
}

storiesOf('component', module)
  .addDecorator(withKnobs)
  .addDecorator(
    moduleMetadata({
      imports: [FormsModule],
      declarations: [SimpleComponent],
    }),
  )
  .add('notWorking', () => ({
    component: SimpleComponent,
    props: {
      name: text('Name', 'outer name'),
    },
  }));

System:

Below I expected to see ‘Updated’ (which is the value typed in the knob)next to the input but it still shows the default value image

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:9

github_iconTop GitHub Comments

3reactions
Silveriumcommented, Jun 18, 2020

Hi all,

I’ve found a workaround. Use functions!! As you may know, React is all about functions and so are knobs, with this approach, you have instant responsiveness:

...
  .add('your story here', () => ({
    template: `
        <your-component-here
                [customHeight]="height()">
        </your-component-here>
    `,
    props: {
      height: () => number('height', 50)
    },
  }));
3reactions
blemairecommented, May 30, 2019

Hey, has anybody had a chance to look at this? It’s not blocking as we can wrap the component in a template but it’s extra effort to duplicate the bindings when they’re already there. Thanks a lot

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 5 Component Not Updating When Observable Returns
I decided to attempted to run ChangeDetectorRef.detectChanges(); after I update the property of the component. Doing this actually fixed my ...
Read more >
Angular Semi Knob not working - Forums - jQWidgets
Hello iwagner, The issue seems to come from the setup of the Angular Application, rather than the Knob element. projects. $projectName.
Read more >
Observables compared to other techniques - Angular
Observables are declarative; computation does not start until subscription. Promises execute immediately on creation. · Observables provide many values.
Read more >
Security - Angular
This topic describes Angular's built-in protections against common web-application vulnerabilities and attacks such as cross-site scripting attacks.
Read more >
Adding navigation - Angular
View product detailslink. The ProductDetailsComponent handles the display of each product. The Angular Router displays components based on the browser's URL and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found