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

reuse filters across components #173

Open
Aliaksandr-Padabed opened this issue Mar 28, 2018 · 1 comment
Open

reuse filters across components #173

Aliaksandr-Padabed opened this issue Mar 28, 2018 · 1 comment

Comments

@Aliaksandr-Padabed
Copy link

For example I have two components which use same filter. It is not clear from the styleguide should I duplicate filter code in each module, or move filter to parent/root module? Or create something like common.module to keep reusable code?
From performance point of view keeping filters as separate files in common folder (not in common module) is better because filter will not be included in every bundle.

@Mic75
Copy link

Mic75 commented Apr 11, 2018

@Aliaksandr-Padabed Agreed with you. I encounter the exact same situation with a shared filter and a shared service. For example, let's say I have a custom loggerService that I would like to use accross different components. The styleguide does not mention where to put it.

The styleguide considers an AngularJS application as a cluster of isolated components which can communicate with each other. But, it feels like it's missing a part about the application wide shared code .

Anyway, I ended up attaching my service and my filter to the app.components module like this:

export default angular
  .module('app.components', [
    ProjectModule,
    LearnModule,
  ])
  .filter('mySharedFilter', SharedFilter)
  .service('mySharedService', SharedService)
  .name;

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

No branches or pull requests

2 participants