Directives should support module publishing. #652
Description
When the directive is trigger its annotation should allow for modules which would be merged into the injector. In this way the directive could do more then just instantiate itself. It could also override instances, or create a whole collection of instances.
This should replace publishTypes annotation property.
We have a publishTypes
https://docs.angulardart.org/#angular/angular.NgAnnotation@id_publishTypes annotation.
It is used like this
@NgDirective({
publishTypes: [SomeInterface]
})
class SomeDirective implements SomeInterface {
}
The reason for this is that if we could have multiple directives which implement SomeInterface
we would like for to inject it as SomeInterface
. The issue is that when the module gets registered it will say something like this:
module.type(SomeDirective)
This means that asking for SomeInterface
will return error. What the publishTypes
property does is do an extra registration like so:
module.type(SomeDirective)
module.factory(SomeInterface, (i) => i.get(SomeDirective));
This enables one to ask for SomeInterface
and get SomeDirective
implementation.
But this is really just one specific use case. A more generic case is that a Directive should be able to create a custom module definition which should be loaded into the injector. Then the directive can performa a lot more.
Something like so:
@NgDirective({
module: SomeDirective.module;
})
class SomeDirective implements SomeInterface {
static _module = new Module()
..factory(SomeInterface, (i) => i.get(SomeDirective))
..type(SomeOtherType)
static module() => _module;
}
This way not only can a directive implement different types, but it can also publish its own types.