diff --git a/modules/angular2/src/core/annotations/di.js b/modules/angular2/src/core/annotations/di.js index 1f5fec6e12..dbe1ce7143 100644 --- a/modules/angular2/src/core/annotations/di.js +++ b/modules/angular2/src/core/annotations/di.js @@ -12,6 +12,10 @@ export class EventEmitter extends DependencyAnnotation { super(); this.eventName = eventName; } + + get token() { + return Function; + } } /** @@ -25,6 +29,10 @@ export class PropertySetter extends DependencyAnnotation { super(); this.propName = propName; } + + get token() { + return Function; + } } /** diff --git a/modules/angular2/src/di/annotations.js b/modules/angular2/src/di/annotations.js index d2197918bd..1bc253637a 100644 --- a/modules/angular2/src/di/annotations.js +++ b/modules/angular2/src/di/annotations.js @@ -107,6 +107,10 @@ export class DependencyAnnotation { @CONST() constructor() { } + + get token() { + return null; + } } /** diff --git a/modules/angular2/src/di/binding.js b/modules/angular2/src/di/binding.js index 9661566526..efd709133d 100644 --- a/modules/angular2/src/di/binding.js +++ b/modules/angular2/src/di/binding.js @@ -135,7 +135,11 @@ function _extractToken(typeOrFunc, annotations) { optional = true; } else if (paramAnnotation instanceof DependencyAnnotation) { + if (isPresent(paramAnnotation.token)) { + token = paramAnnotation.token; + } 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 03dff1b768..d99352df29 100644 --- a/modules/angular2/test/core/compiler/element_injector_spec.js +++ b/modules/angular2/test/core/compiler/element_injector_spec.js @@ -79,6 +79,16 @@ class NeedsEventEmitter { } } +class NeedsEventEmitterNoType { + clickEmitter; + constructor(@EventEmitter('click') clickEmitter) { + this.clickEmitter = clickEmitter; + } + click() { + this.clickEmitter(null); + } +} + class NeedsPropertySetter { propSetter; roleSetter; @@ -113,6 +123,17 @@ class NeedsPropertySetter { } } +class NeedsPropertySetterNoType { + propSetter; + constructor(@PropertySetter('title') propSetter) { + this.propSetter = propSetter; + } + + setProp(value) { + this.propSetter(value); + } +} + class NeedsAttribute { typeAttribute; titleAttribute; @@ -545,24 +566,43 @@ export function main() { }); describe('event emitters', () => { - it('should be injectable and callable', () => { - var called = false; + + function createpreBuildObject(eventName, eventHandler) { var handlers = StringMapWrapper.create(); - StringMapWrapper.set(handlers, 'click', (e, view) => { called = true;}); + StringMapWrapper.set(handlers, eventName, eventHandler); var pv = new ProtoView(null, null, null); pv.eventHandlers = [handlers]; var view = new View(pv, null, MapWrapper.create()); - var preBuildObject = new PreBuiltObjects(view, null, null, null); + return new PreBuiltObjects(view, null, null, null); + } + + it('should be injectable and callable', () => { + var called = false; + var preBuildObject = createpreBuildObject('click', (e, view) => { called = true;}); var inj = injector([NeedsEventEmitter], null, null, preBuildObject); inj.get(NeedsEventEmitter).click(); expect(called).toEqual(true); }); + it('should be injectable and callable without specifying param type annotation', () => { + var called = false; + var preBuildObject = createpreBuildObject('click', (e, view) => { called = true;}); + var inj = injector([NeedsEventEmitterNoType], null, null, preBuildObject); + inj.get(NeedsEventEmitterNoType).click(); + expect(called).toEqual(true); + }); + it('should be queryable through hasEventEmitter', () => { var inj = injector([NeedsEventEmitter]); expect(inj.hasEventEmitter('click')).toBe(true); expect(inj.hasEventEmitter('move')).toBe(false); }); + + it('should be queryable through hasEventEmitter without specifying param type annotation', () => { + var inj = injector([NeedsEventEmitterNoType]); + expect(inj.hasEventEmitter('click')).toBe(true); + expect(inj.hasEventEmitter('move')).toBe(false); + }); }); describe('property setter', () => { @@ -577,7 +617,7 @@ export function main() { component.setRole('button'); component.setClass(true); component.classWithDashSetter(true); - component.setStyle('40px') + component.setStyle('40px'); component.setStyleWithUnit(50); expect(div.title).toEqual('foobar'); @@ -587,6 +627,16 @@ export function main() { expect(DOM.getStyle(div, 'width')).toEqual('40px'); expect(DOM.getStyle(div, 'height')).toEqual('50px'); }); + + it('should be injectable and callable without specifying param type annotation', () => { + var div = el('
'); + var preBuildObject = new PreBuiltObjects(null, new NgElement(div), null, null); + var inj = injector([NeedsPropertySetterNoType], null, null, preBuildObject); + var component = inj.get(NeedsPropertySetterNoType); + component.setProp('foobar'); + + expect(div.title).toEqual('foobar'); + }); }); describe('static', () => {