JavaScript Abstracting duplicate controller logic into service

I ended up doing the following, but I'm open to other solutions as I'm not sure this is idiomatic Angular:

.controller('CtrlOne', function(filterHandler) {
  this.filters = [...]; // this data is unique for controller one
  this.filterHandler = filterHandler.create(this.filters);
})

.controller('CtrlTwo', function(filterHandler) {
  this.filters = [...]; // this data is unique for controller two
  this.filterHandler = filterHandler.create(this.filters);
})

.directive('filtering', function() {
  return {
    restrict: 'E',
    templateUrl: 'filtering.html',
    scope: {},
    bindToController: {
      filters: '=',
      onChangeFilter: '=',
      onShowFilter: '='
    },
    controllerAs: 'filtering',
    controller: function() {
    }
  }
})

.service('filterHandler', function() {
  return {
    create: function() {
      var isAllSelected = true;
      return {
        change: function(selected) {
          ...
        },
        show: function(filter) {
          ...
        }
      };
    }
  }
})

// filtering.html
`
<ul>
  <li ng-repeat="filter in filtering.filters"
      ng-click="filtering.onChangeFilter(filter)"
      ng-show="filtering.onShowFilter(filter)">
    <span ng-style="{color: filter.isActive ? 'red' : 'inherit'}">
      {{filter.name}}
    </span>
  </li>
</ul>
`

// Using the filtering directive
`
<filtering
  on-change-filter="::ctrlOne.filterHandler.change"
  on-show-filter="::ctrlOne.filterHandler.show"
  filters="::ctrlOne.filters">
</filtering>
`
Answer:1

I have a function that writes a file to a directory: response.pipe(fs.createWriteStream(fullPath)) But before that I want to check if the path already exist, and if so, add a suffix, e.g. file_1.txt ...

I have a function that writes a file to a directory: response.pipe(fs.createWriteStream(fullPath)) But before that I want to check if the path already exist, and if so, add a suffix, e.g. file_1.txt ...

I have the following markup: <li data-group="bottoms">Pants</li> <li data-group="bottoms">Pants</li> <li data-group="bottoms">Pants</li> <li data-group="tops"&...

I have the following markup: <li data-group="bottoms">Pants</li> <li data-group="bottoms">Pants</li> <li data-group="bottoms">Pants</li> <li data-group="tops"&...

  1. returning unique values from a list in excel
  2. sql return unique values

I am writing an Android app that requires access to a MySql server. Following examples I have found, I have a php page that sits on the server and does the MySql stuff, and I try to access that from ...

I am writing an Android app that requires access to a MySql server. Following examples I have found, I have a php page that sits on the server and does the MySql stuff, and I try to access that from ...

  1. android gets hot
  2. android gets hot while charging
  3. android gets slower over time
  4. android gets hot and battery drains
  5. android gets citizenship
  6. android gets ads
  7. android gets stuck on boot screen
  8. android gets hacked
  9. android gets virus
  10. android gets fido2 certification
  11. android gets slow sometimes
  12. android gets black screen
  13. android get iphone apps
  14. android gets focus
  15. android gets stuck on startup
  16. android gets screen width
  17. android gets lag
  18. android phone gets hot
  19. android auto gets disconnected
  20. android 18 gets absorbed by cell

I have a map like this for example const Map = new Map().set('123', [ [ 'foo', 'bar' ] ]).set('456', [ [ 'baz', 'qux' ], [ 'quux', 'corge' ] ]); /* The structure of the Map looks like this: Map {...

I have a map like this for example const Map = new Map().set('123', [ [ 'foo', 'bar' ] ]).set('456', [ [ 'baz', 'qux' ], [ 'quux', 'corge' ] ]); /* The structure of the Map looks like this: Map {...