davej / angular-classy

Cleaner class-based controllers with Angular 1
http://davej.github.io/angular-classy/
813 stars 27 forks source link

Remove the 'classy' dependency checking in child module when parent module already have it. #28

Closed ghost closed 10 years ago

ghost commented 10 years ago

If I my parent angular module depends on 'classy', I don't want my child modules also depends on 'classy'. It repeats the code, doesn't make sense at all.

MikaAK commented 10 years ago

I agree with this, If I'm to use classy in everything I should just be able to add it as a dependancy inside of my app.js and not have to require it in every individual controller, its not DRY!

Is this a good reason not to do this?

davej commented 10 years ago

Can you give me a code example for this please?

MikaAK commented 10 years ago
angular.module('baseModule', ['ui.router', 'classy', 'firstModule])
  .config(function($stateProvider) {
    $stateProvider
      .state('first', {
        url: '/first',
        controller: 'firstCtrl',
        template: '<h1> Hello World</h1>
      })
  })
// This will not work because firstModule doesn't have the classy dependency
angular.module('firstModule', [])
  .classy.controller({
    name: 'firstCtrl',
    inject: ['$scope'],
  })

Basically my hope is that if you inject classy into the baseModule it would not needed to be included in every new module for controllers.

davej commented 10 years ago

Is the code from the second snippet supposed to include baseModule as a require:

// This will not work because firstModule doesn't have the classy dependency
angular.module('firstModule', ['baseModule'])
  .classy.controller({
    name: 'firstCtrl',
    inject: ['$scope'],
  })
MikaAK commented 10 years ago

No it wouldn't. See JSBin for example injection

davej commented 10 years ago

@MikaAK: Ok, I see what you mean now. I think I would prefer to keep it explicit rather than introduce logic which would make it implicit.

I actually think @bwu-aa's original issue was different so I will keep this issue open. I believe @bwu-aa's issue was with code like this:


angular.module('baseModule', ['classy']);

angular.module('anotherModule', ['baseModule']).classy; // Doesn't work
lovanwubing commented 10 years ago

Yes, that's what I mean. Thanks. (this is my another account for bwu-aa which is used in my company, sorry for this.)

davej commented 10 years ago

Fixed in beta 5