@@ -61,7 +61,7 @@ angular.module('schemaForm')
61
61
//Since we are dependant on up to three
62
62
//attributes we'll do a common watch
63
63
var lastDigest = { } ;
64
-
64
+ var childScope ;
65
65
scope . $watch ( function ( ) {
66
66
67
67
var schema = scope . schema ;
@@ -77,8 +77,17 @@ angular.module('schemaForm')
77
77
var merged = schemaForm . merge ( schema , form , ignore , scope . options ) ;
78
78
var frag = document . createDocumentFragment ( ) ;
79
79
80
+ // Create a new form and destroy the old one.
81
+ // Not doing keeps old form elements hanging around after
82
+ // they have been removed from the DOM
83
+ // https://github.com/Textalk/angular-schema-form/issues/200
84
+ if ( childScope ) {
85
+ childScope . $destroy ( ) ;
86
+ }
87
+ childScope = scope . $new ( ) ;
88
+
80
89
//make the form available to decorators
81
- scope . schemaForm = { form : merged , schema : schema } ;
90
+ childScope . schemaForm = { form : merged , schema : schema } ;
82
91
83
92
//clean all but pre existing html.
84
93
element . children ( ':not(.schema-form-ignore)' ) . remove ( ) ;
@@ -117,7 +126,7 @@ angular.module('schemaForm')
117
126
element [ 0 ] . appendChild ( frag ) ;
118
127
119
128
//compile only children
120
- $compile ( element . children ( ) ) ( scope ) ;
129
+ $compile ( element . children ( ) ) ( childScope ) ;
121
130
122
131
//ok, now that that is done let's set any defaults
123
132
schemaForm . traverseSchema ( schema , function ( prop , path ) {
0 commit comments