feat(element_injector): allow @Optional for ProtoViewRef
This commit is contained in:
@@ -150,6 +150,13 @@ class NeedsProtoViewRef {
|
||||
}
|
||||
}
|
||||
|
||||
class OptionallyInjectsProtoViewRef {
|
||||
protoViewRef;
|
||||
constructor(@Optional() ref:ProtoViewRef) {
|
||||
this.protoViewRef = ref;
|
||||
}
|
||||
}
|
||||
|
||||
class NeedsChangeDetectorRef {
|
||||
changeDetectorRef;
|
||||
constructor(cdr:ChangeDetectorRef) {
|
||||
@@ -811,6 +818,12 @@ export function main() {
|
||||
() => injector([NeedsProtoViewRef])
|
||||
).toThrowError('No provider for ProtoViewRef! (NeedsProtoViewRef -> ProtoViewRef)');
|
||||
});
|
||||
|
||||
it('should inject null if there is no ProtoViewRef when the dependency is optional', () => {
|
||||
var inj = injector([OptionallyInjectsProtoViewRef]);
|
||||
var instance = inj.get(OptionallyInjectsProtoViewRef);
|
||||
expect(instance.protoViewRef).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('directive queries', () => {
|
||||
|
||||
Reference in New Issue
Block a user