Skip to content
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 - Add component story with dependencies #2514

Closed
felipe-norato opened this issue Dec 19, 2017 · 9 comments
Closed

Angular - Add component story with dependencies #2514

felipe-norato opened this issue Dec 19, 2017 · 9 comments
Labels

Comments

@felipe-norato
Copy link

felipe-norato commented Dec 19, 2017

Issue details

I had some errors when I try to create a story for a component that has dependencies, like pipes and directives.

Version of Storybook and optionally any affected addons that you're running

  • storybook/addon-actions ^3.3.0-alpha.4
  • storybook/addon-knobs ^3.3.0-alpha.4
  • storybook/addon-links ^3.3.0-alpha.4
  • storybook/addon-notes ^3.3.0-alpha.4
  • storybook/addons ^3.3.0-alpha.4
  • storybook/angular ^3.3.0-alpha.4
  • angular/cli 1.6.0

Code Snippets

// Main module
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';


import { AppComponent } from './app.component';
import { CustomDirectiveDirective } from './custom-directive.directive';
import { CustomPipePipe } from './custom-pipe.pipe';


@NgModule({
  declarations: [
    AppComponent,
    CustomDirectiveDirective,
    CustomPipePipe
  ],
  imports: [
    BrowserModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

// Pipe
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'customPipe'
})
export class CustomPipePipe implements PipeTransform {

  transform(value: any, args?: any): any {
    return value;
  }
}


// Component

import { Component, OnInit, Directive } from '@angular/core';

@Component({
  selector: 'selector-name',
  template: `<h1>{{ 'foobar' | customPipe }}</h1>`
})

export class NameComponent {}

// Story
import { storiesOf } from '@storybook/angular';

storiesOf('NameComponent', module)
  .add('with text', () => ({
    component: NameComponent,
    props: { }
}))

Returns the dependency injection error

The pipe 'customPipe' could not be found ("<!--The content below is only a placeholder and can be replaced.--><h1>{{ [ERROR ->]'title' | customPipe }}!</h1
@igor-dv
Copy link
Member

igor-dv commented Dec 19, 2017

What is the angular version in this case ? Can you elaborate where the error is happening ?

@felipe-norato
Copy link
Author

@igor-dv It's angular 5.0.0
This is the same error when miss the dependency injector for the pipe.
In the first comment I attach module code.

@igor-dv
Copy link
Member

igor-dv commented Dec 19, 2017

I've added a PR to fix this. Thanks !

@felipe-norato
Copy link
Author

Amazing, man!
Thanks for you help!

@felipe-norato
Copy link
Author

@igor-dv Found the same behavior for apply a directive with input

Code Snippets

// Directive
import { Directive, Input } from '@angular/core';

@Directive({
  selector: '[appCustomDirective]'
})
export class CustomDirectiveDirective {
  @Input() directiveAttr: number;
}

// Component

import { Component, OnInit, Directive } from '@angular/core';

@Component({
  selector: 'selector-name',
  template: `<div appCustomDirective [directiveAttr]='"foobar"' >has directive with attr</div>`
})

export class NameComponent {}

// Story
import { storiesOf } from '@storybook/angular';

storiesOf('NameComponent', module)
  .add('with text', () => ({
    component: NameComponent,
    props: { }
}))

Console error

div(appCustomDirective, [directiveAttr]='foobar') has directive with attr

@igor-dv
Copy link
Member

igor-dv commented Dec 20, 2017

Yeah. I think @alterx have a more robust solution for the other missing features. Once #2467 will be finished we will take care of other stuff. Thanks for the feedback, if you have more of them, please write about it, we need more testers =)

@alterx
Copy link
Member

alterx commented Dec 20, 2017

Yup, @noratodaitan, we have a solution coming that will allow people to inject schemas, providers et al (basically everything you can include in a NgModule).

@felipe-norato
Copy link
Author

That sounds great, I will write more tests here.

@alterx alterx added the angular label Dec 20, 2017
@alterx
Copy link
Member

alterx commented Dec 20, 2017

@noratodaitan here's the PR #2526
We still need to test some stuff but please do give it a spin and let us know how that goes :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants