@@ -69,22 +69,14 @@ angular.module('angular-json-editor', []).provider('JSONEditor', function () {
69
69
}
70
70
} ] ,
71
71
link : function ( scope , element , attrs , controller , transclude ) {
72
- var startValPromise = $q . when ( { } ) ,
73
- schemaPromise = $q . when ( null ) ;
72
+ var startValPromise = $q . when ( scope . startval ) ,
73
+ schemaPromise = $q . when ( scope . schema ) ;
74
74
75
75
scope . isValid = false ;
76
76
77
77
if ( ! angular . isString ( attrs . schema ) ) {
78
78
throw new Error ( 'angular-json-editor: schema attribute has to be defined.' ) ;
79
79
}
80
- if ( angular . isObject ( scope . schema ) ) {
81
- schemaPromise = $q . when ( scope . schema ) ;
82
- }
83
- if ( angular . isObject ( scope . startval ) ) {
84
- // Support both $http (i.e. $q) and $resource promises, and also normal object.
85
- startValPromise = $q . when ( scope . startval ) ;
86
- }
87
-
88
80
// Wait for the start value and schema to resolve before building the editor.
89
81
$q . all ( [ schemaPromise , startValPromise ] ) . then ( function ( result ) {
90
82
@@ -129,21 +121,36 @@ angular.module('angular-json-editor', []).provider('JSONEditor', function () {
129
121
} ) ;
130
122
}
131
123
132
- restart ( startVal , schema ) ;
124
+ restart ( ) ;
133
125
134
- scope . $watch ( 'schema' , function ( newVal , oldVal ) {
126
+ // update schema if changed
127
+ scope . $watch ( 'schema' , function ( newVal ) {
135
128
//update newScheme
136
- if ( newVal . success ) {
137
- newVal . success ( function ( data ) {
129
+ if ( newVal . then ) {
130
+ newVal . then ( function ( data ) {
138
131
schema = data ;
132
+ restart ( ) ;
139
133
} ) ;
140
134
} else {
141
135
schema = newVal ;
136
+ restart ( ) ;
142
137
}
143
-
144
- restart ( ) ;
145
138
} , true ) ;
146
139
140
+ // update schema if promise
141
+ scope . $watchCollection ( 'schema' , function ( newVal ) {
142
+ if ( newVal instanceof $q ) {
143
+ newVal . then ( function ( data ) {
144
+ if ( data . data ) {
145
+ schema = data . data ;
146
+ } else {
147
+ schema = data ;
148
+ }
149
+ restart ( ) ;
150
+ } ) ;
151
+ }
152
+ } ) ;
153
+
147
154
// Transclude the buttons at the bottom.
148
155
var buttons = transclude ( scope , function ( clone ) {
149
156
return clone ;
0 commit comments