Ionic-framework: See if we can automatically inject IONIC_DIRECTIVES

Created on 8 Apr 2016  路  6Comments  路  Source: ionic-team/ionic-framework

We should be able to add IONIC_DIRECTIVES so that users can create custom components without having to import them.

Most helpful comment

I don't think we should. This kind of goes against the whole import/explicit idea.
The generate command automatically includes IONIC_DIRECTIVES, so I think we could do a better job documenting that feature, or adding a section to the docs about them.

All 6 comments

I don't think we should. This kind of goes against the whole import/explicit idea.
The generate command automatically includes IONIC_DIRECTIVES, so I think we could do a better job documenting that feature, or adding a section to the docs about them.

It was something @adamdbradley mentioned adding the other day. I think it's confusing that we do it for them in @App and @Page and then they have to figure out what they're missing when the styles don't work in their @Component.

As a beginner to Ionic 2 and Angular 2, I spent a fair amount of time wondering why my Angular component wasn't playing nice with Ionic. At first I thought it was about wrapping the whole component in an <ion-content> or changing @Component to something else like @IonicComponent, but only after a substantial amount of time I understood the whole concept of DI through it and why IONIC_DIRECTIVES are important. Hope that helps! 馃槃

You could also add the directives to the PLATFORM_DIRECTIVES DI token during bootstrap. This way they would be available in all components.

Thanks @frederikschubert, we did exactly that

@adamdbradley I would have liked to have the auto provide sooner, i had to use something like this for NorificatorComponent (ugly as hell):

// Components
import {BusyComponent, BusyCtrl, NotificatorComponent} from './components/components'
@App({
  templateUrl: 'build/app.html',
  providers: [
    BusyCtrl,
    provide(PLATFORM_DIRECTIVES, {useValue: [NotificatorComponent], multi: true})
  ],
  directives: [BusyComponent]
})

I guess now i can just stick it inside the directives array and it will be global now, right?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Nick-The-Uncharted picture Nick-The-Uncharted  路  3Comments

daveshirman picture daveshirman  路  3Comments

vswarte picture vswarte  路  3Comments

SebastianGiro picture SebastianGiro  路  3Comments

alan-agius4 picture alan-agius4  路  3Comments