2525import * as _ from 'lodash' ;
2626import {
2727 ComponentFactoryResolver ,
28+ ComponentRef ,
2829 Directive ,
2930 Input ,
3031 OnDestroy ,
@@ -38,7 +39,7 @@ import {
3839 JsonFormsProps , JsonFormsState ,
3940 JsonSchema ,
4041 mapStateToJsonFormsRendererProps ,
41- OwnPropsOfRenderer ,
42+ OwnPropsOfRenderer
4243} from '@jsonforms/core' ;
4344import { NgRedux } from '@angular-redux/store' ;
4445import 'rxjs/add/operator/map' ;
@@ -53,6 +54,7 @@ import { JsonFormsControl } from './control';
5354export class JsonFormsOutlet extends JsonFormsBaseRenderer implements OnInit , OnDestroy {
5455
5556 private subscription : Subscription ;
57+ private componentRef : ComponentRef < any > ;
5658
5759 constructor (
5860 private viewContainerRef : ViewContainerRef ,
@@ -95,13 +97,16 @@ export class JsonFormsOutlet extends JsonFormsBaseRenderer implements OnInit, On
9597 if ( renderer !== undefined && renderer . tester ( uischema , schema ) !== - 1 ) {
9698 bestComponent = renderer . renderer ;
9799 }
98- const componentFactory =
99- this . componentFactoryResolver . resolveComponentFactory ( bestComponent ) ;
100- this . viewContainerRef . clear ( ) ;
101100
102- const componentRef = this . viewContainerRef . createComponent ( componentFactory ) ;
103- if ( componentRef . instance instanceof JsonFormsBaseRenderer ) {
104- const instance = ( componentRef . instance as JsonFormsBaseRenderer ) ;
101+ if ( this . componentRef === undefined ) {
102+ const componentFactory =
103+ this . componentFactoryResolver . resolveComponentFactory ( bestComponent ) ;
104+ this . viewContainerRef . clear ( ) ;
105+ this . componentRef = this . viewContainerRef . createComponent ( componentFactory ) ;
106+ }
107+
108+ if ( this . componentRef . instance instanceof JsonFormsBaseRenderer ) {
109+ const instance = ( this . componentRef . instance as JsonFormsBaseRenderer ) ;
105110 instance . uischema = uischema ;
106111 instance . schema = schema ;
107112 instance . path = this . path ;
0 commit comments