注释不是继承的,所以如果你有:
@Directive({
selector:'foo',
inputs:['bar']
})
export class Foo {}
//no annotation
export class FooBar extends Foo {} //not a directive
@Directive({
selector:'foobaz'
})
export class FooBaz extends Foo {} //is a directive, but has no inputs
FooBar
will not be recognized as a directive at all, and FooBaz
will but it won't the bar
input (or any others). So, if inheritance is really what makes the most sense for your use-case, the way to approach this would be to declare inputs etc. in the child class annotations and pass them as constructor arguments to the parent class, where you can encapsulate common functionality.
That said, I don't think extensibility necessarily implies inheritance, and in my experience the old adage "favor composition over inheritance" is doubly true when DI is involved.
Someone much smarter than me recently said, "inheritance will murder your children in their sleep", and I tend to adhere to that viewpoint myself unless I'm damn sure it's the right tool for my use-case.