diff --git a/modules/angular2/src/core/annotations/di.js b/modules/angular2/src/core/annotations/di.js index dbe1ce7143..bf9ad88f06 100644 --- a/modules/angular2/src/core/annotations/di.js +++ b/modules/angular2/src/core/annotations/di.js @@ -45,4 +45,12 @@ export class Attribute extends DependencyAnnotation { super(); this.attributeName = attributeName; } + + get token() { + //Normally one would default a token to a type of an injected value but here + //the type of a variable is "string" and we can't use primitive type as a return value + //so we use instance of Attribute instead. This doesn't matter much in practice as arguments + //with @Attribute annotation are injected by ElementInjector that doesn't take tokens into account. + return this; + } } diff --git a/modules/angular2/src/di/binding.js b/modules/angular2/src/di/binding.js index efd709133d..684b97b6cd 100644 --- a/modules/angular2/src/di/binding.js +++ b/modules/angular2/src/di/binding.js @@ -140,8 +140,6 @@ function _extractToken(typeOrFunc, annotations) { } ListWrapper.push(depProps, paramAnnotation); - } else if (paramAnnotation.name === "string") { - token = paramAnnotation; } } diff --git a/modules/angular2/test/core/compiler/element_injector_spec.js b/modules/angular2/test/core/compiler/element_injector_spec.js index d99352df29..9998ef71ac 100644 --- a/modules/angular2/test/core/compiler/element_injector_spec.js +++ b/modules/angular2/test/core/compiler/element_injector_spec.js @@ -145,6 +145,13 @@ class NeedsAttribute { } } +class NeedsAttributeNoType { + fooAttribute; + constructor(@Attribute('foo') fooAttribute) { + this.fooAttribute = fooAttribute; + } +} + class A_Needs_B { constructor(dep){} } @@ -639,7 +646,7 @@ export function main() { }); }); - describe('static', () => { + describe('static attributes', () => { it('should be injectable', () => { var attributes = MapWrapper.create(); MapWrapper.set(attributes, 'type', 'text'); @@ -652,6 +659,16 @@ export function main() { expect(needsAttribute.titleAttribute).toEqual(''); expect(needsAttribute.fooAttribute).toEqual(null); }); + + it('should be injectable without type annotation', () => { + var attributes = MapWrapper.create(); + MapWrapper.set(attributes, 'foo', 'bar'); + + var inj = injector([NeedsAttributeNoType], null, null, null, attributes); + var needsAttribute = inj.get(NeedsAttributeNoType); + + expect(needsAttribute.fooAttribute).toEqual('bar'); + }); }); });