diff --git a/index.tsx b/index.tsx index 51460e7..2d6f19b 100644 --- a/index.tsx +++ b/index.tsx @@ -17,7 +17,8 @@ import { render, unmountComponentAtNode } from 'react-dom' */ export function react2angular( Class: React.ComponentClass | React.SFC, - bindingNames?: (keyof Props)[] + bindingNames: (keyof Props)[] | null = null, + injectNames: string[] = [] ): IComponentOptions { const names = bindingNames || (Class.propTypes && Object.keys(Class.propTypes)) @@ -25,13 +26,15 @@ export function react2angular( return { bindings: fromPairs(names.map(_ => [_, '<'])), - controller: ['$element', class extends NgComponent { - constructor(private $element: IAugmentedJQuery) { + controller: ['$element', ...(injectNames as any), class extends NgComponent { + injectedProps: any[]; + constructor(private $element: IAugmentedJQuery, ...injectedProps: any[]) { super() + this.injectedProps = injectedProps; } render() { // TODO: rm any when https://github.com/Microsoft/TypeScript/pull/13288 is merged - render(, this.$element[0]) + render(, this.$element[0]) } componentWillUnmount() { unmountComponentAtNode(this.$element[0]) diff --git a/test.tsx b/test.tsx index 3310094..bd19ef4 100644 --- a/test.tsx +++ b/test.tsx @@ -114,6 +114,18 @@ describe('react2angular', () => { it('should have empty bindings when parameter is not passed', () => { expect(react2angular(TestThree).bindings).toEqual({}) }) + + it('should use the injectNames for DI', () => { + const defaultDi = (react2angular(TestThree).controller as any).slice(0, -1) + const injectedDi = (react2angular(TestThree, null, ['foo', 'bar']).controller as any).slice(0, -1) + expect(injectedDi).toEqual(defaultDi.concat(['foo', 'bar'])) + }) + + it('should have default DI specifications if injectNames is empty', () => { + const defaultDi = (react2angular(TestThree).controller as any).slice(0, -1) + const injectedDi = (react2angular(TestThree, null, []).controller as any).slice(0, -1) + expect(injectedDi).toEqual(defaultDi) + }) }) describe('react classes', () => {