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

Using the 'appInjector' property in @Component as an alias to adding module deps #19

Closed
timkindberg opened this issue Jul 10, 2015 · 0 comments

Comments

@timkindberg
Copy link
Contributor

The latest Angular 2 has renamed injectables to appInjector. See: https://angular.io/docs/js/latest/api/annotations/ComponentAnnotation-class.html.

In addition to renaming this, I think we should consider allowing appInjector to take not only string-based ng1 injectables (e.g. '$http') but also a1atscript created injectables (e.g. Greeter).

For example, currently we do this:

@Service('greeter')
class Greeter {}

@AsModule('GreetCmpt', [Greeter])
@Component({
  selector: 'greet',
  injectables: ['$http', 'greeter']
})
class HelloWorld {
  constructor($http, greeter) {
    this.greeter = greeter;
  }
}

We have to add the Greeter service as a module dependency on the Greet component's module. Then also add it to injectables. Seems like we could reduce some boilerplate here.

We should be able to do this:

@Service
class Greeter {}

@Component({
  selector: 'greet',
  appInjector: ['$http', Greeter]
})
class HelloWorld {
  constructor($http, greeter) {
    this.greeter = greeter;
  }
}

In this example I've renamed injectables to appInjector but I've now added the ability to not only inject string-based things like '$http' but also the Greeter service. This more closely matches how ng2 uses classes instead of strings. Also, notice I left out the @AsModule because it should be able to grab the module off of the Greeter class passed into the appInjector.

So the acceptance criteria for this feature would be:

  1. Rename injectables to appInjector
  2. Allow passing a1atscript class-based injectables in addition to string-based regular ng1 injectables
  3. Add the modules from a1atscript classes in appInjector to the dependencies of the auto-generated module of the host class.
  4. If @AsModule is present then merge the dependencies, also allow @AsModule to only specify a name and no dependencies, e.g. @AsModule("GreetComponent")
@timkindberg timkindberg changed the title Using the 'appInjector' property in @Component as an alias to adding modules Using the 'appInjector' property in @Component as an alias to adding module deps Jul 10, 2015
hannahhoward added a commit that referenced this issue Jul 19, 2015
Fixes #19 - appInjector as property for injections
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

1 participant