@@ -19,15 +19,16 @@ import {
1919
2020import { SchemaValidatorFactory , ZSchemaValidatorFactory } from './schemavalidatorfactory' ;
2121import { WidgetFactory } from './widgetfactory' ;
22+ import { TerminatorService } from './terminator.service' ;
2223
2324export function useFactory ( schemaValidatorFactory , validatorRegistry ) {
2425 return new FormPropertyFactory ( schemaValidatorFactory , validatorRegistry ) ;
2526} ;
2627
2728@Component ( {
2829 selector : 'sf-form' ,
29- template : `<sf-form-element
30- *ngIf="rootProperty" [formProperty]="rootProperty"></sf-form-element>` ,
30+ template : `<form>< sf-form-element
31+ *ngIf="rootProperty" [formProperty]="rootProperty"></sf-form-element></form> ` ,
3132 providers : [
3233 ActionRegistry ,
3334 ValidatorRegistry ,
@@ -40,7 +41,8 @@ export function useFactory(schemaValidatorFactory, validatorRegistry) {
4041 provide : FormPropertyFactory ,
4142 useFactory : useFactory ,
4243 deps : [ SchemaValidatorFactory , ValidatorRegistry ]
43- }
44+ } ,
45+ TerminatorService ,
4446 ]
4547} )
4648export class FormComponent implements OnChanges {
@@ -61,11 +63,11 @@ export class FormComponent implements OnChanges {
6163 private formPropertyFactory : FormPropertyFactory ,
6264 private actionRegistry : ActionRegistry ,
6365 private validatorRegistry : ValidatorRegistry ,
64- private cdr : ChangeDetectorRef
66+ private cdr : ChangeDetectorRef ,
67+ private terminator : TerminatorService ,
6568 ) { }
6669
6770 ngOnChanges ( changes : any ) {
68- console . log ( changes ) ;
6971 if ( changes . validators ) {
7072 this . setValidators ( ) ;
7173 }
@@ -74,12 +76,14 @@ export class FormComponent implements OnChanges {
7476 this . setActions ( ) ;
7577 }
7678
77- if ( ! this . schema . type ) {
79+ if ( this . schema && ! this . schema . type ) {
7880 this . schema . type = 'object' ;
7981 }
8082
8183 if ( this . schema && changes . schema ) {
82- console . log ( this . schema , changes . schema ) ;
84+ if ( ! changes . schema . firstChange ) {
85+ this . terminator . destroy ( ) ;
86+ }
8387 SchemaPreprocessor . preprocess ( this . schema ) ;
8488 this . rootProperty = this . formPropertyFactory . createProperty ( this . schema ) ;
8589 this . rootProperty . valueChanges . subscribe ( value => { this . onChange . emit ( { value : value } ) ; } ) ;
0 commit comments