angularjs-styleguide icon indicating copy to clipboard operation
angularjs-styleguide copied to clipboard

reuse filters across components

Open Aliaksandr-Padabed opened this issue 7 years ago • 1 comments

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.

Aliaksandr-Padabed avatar Mar 28 '18 08:03 Aliaksandr-Padabed

@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;

Mic75 avatar Apr 11 '18 15:04 Mic75