X Tutup
Skip to content

Commit 6514b8c

Browse files
mgechevvsavkin
authored andcommitted
fix(di): allow dependencies as flat array
1 parent c02f2bd commit 6514b8c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

modules/angular2/src/core/di/provider.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,13 @@ function _extractToken(typeOrFunc, metadata /*any[] | any*/, params: any[][]): D
642642
var optional = false;
643643

644644
if (!isArray(metadata)) {
645-
return _createDependency(metadata, optional, null, null, depProps);
645+
if (metadata instanceof InjectMetadata) {
646+
var metaArrayWrapper = ListWrapper.createFixedSize(1);
647+
metaArrayWrapper[0] = metadata;
648+
metadata = metaArrayWrapper;
649+
} else {
650+
return _createDependency(metadata, optional, null, null, depProps);
651+
}
646652
}
647653

648654
var lowerBoundVisibility = null;

modules/angular2/test/core/di/injector_spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,15 @@ export function main() {
648648
});
649649
});
650650

651+
it('should allow declaring dependencies with flat arrays', () => {
652+
var resolved =
653+
Injector.resolve([bind('token').toFactory(e => e, [new InjectMetadata("dep")])]);
654+
var nestedResolved =
655+
Injector.resolve([bind('token').toFactory(e => e, [[new InjectMetadata("dep")]])]);
656+
expect(resolved[0].resolvedFactories[0].dependencies[0].key.token)
657+
.toEqual(nestedResolved[0].resolvedFactories[0].dependencies[0].key.token);
658+
});
659+
651660
describe("displayName", () => {
652661
it("should work", () => {
653662
expect(Injector.resolveAndCreate([Engine, BrokenEngine]).displayName)

0 commit comments

Comments
 (0)
X Tutup