From 0e04a1b0f40aceae0f47cf872b42f5686acccb8f Mon Sep 17 00:00:00 2001 From: domotz_apagiaro Date: Fri, 10 Jul 2020 13:49:39 +0200 Subject: [PATCH] Add support for angular strings --- index.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/index.tsx b/index.tsx index f4067d9..2315923 100644 --- a/index.tsx +++ b/index.tsx @@ -1,6 +1,5 @@ import * as angular from 'angular' import kebabCase = require('lodash.kebabcase') -import { $injector as defaultInjector } from 'ngimport' import * as React from 'react' interface Scope extends angular.IScope { @@ -36,7 +35,6 @@ interface State { export function angular2react( componentName: string, component: angular.IComponentOptions, - $injector = defaultInjector ): React.ComponentClass { return class extends React.Component> { @@ -46,6 +44,7 @@ export function angular2react( } componentWillMount() { + let $injector = angular.element(document.querySelectorAll('[ng-app]')[0]).injector(); this.setState({ scope: Object.assign($injector.get('$rootScope').$new(true), { props: writable(this.props) }) }) @@ -67,7 +66,12 @@ export function angular2react( const bindings: {[key: string]: string} = {} if (component.bindings) { for (const binding in component.bindings) { - bindings[kebabCase(binding)] = `props.${binding}` + if (component.bindings[binding].includes('@')){ + // @ts-ignore + bindings[kebabCase(binding)] = this.props[binding]; + } else { + bindings[kebabCase(binding)] = `props.${binding}`; + } } } return React.createElement(kebabCase(componentName), @@ -89,7 +93,7 @@ export function angular2react( if (this.state.didInitialCompile || !this.state.scope) { return } - + let $injector = angular.element(document.querySelectorAll('[ng-app]')[0]).injector(); $injector.get('$compile')(element)(this.state.scope) this.digest() this.setState({ didInitialCompile: true })