hannahhoward / a1atscript

The Angular 2 Polyfill
MIT License
101 stars 7 forks source link

Adding a 'directives' property in @View that acts as an alias to adding module deps #23

Open timkindberg opened 9 years ago

timkindberg commented 9 years ago

Similar to #19. Except, where appInjector specifies controller-injected dependencies, directives instead specifies which directives (aka Components) are needed for the view. Both are needed as module dependencies though.

See: https://angular.io/docs/js/latest/api/annotations/ComponentAnnotation-class.html for more info on @View.

Instead of using @AsModule to add our component directive dependencies let's use @View directives.

For example, currently we do this:

@Component({ selector: 'foo' })
class Foo {}

@AsModule('Bar', [Foo])
@Component({
  selector: 'bar'
})
@View({
  inline: `<foo></foo>`
})
class Bar { }

We have to add the Foo component as a module dependency on the Bar component's module. Seems like we could achieve the same thing while also following angular 2 api conventions.

We should be able to do this:

@Component({ selector: 'foo' })
class Foo {}

@Component({
  selector: 'bar'
})
@View({
  directives: [Foo],
  inline: `<foo></foo>`
})
class Bar { }

Notice I left out the @AsModule because it should be able to grab the module off of the Foo class passed into the directives property.