Skip to content

Commit 87c8a4b

Browse files
committed
added ajax support for startVal #14
1 parent 986b2f5 commit 87c8a4b

8 files changed

Lines changed: 29 additions & 30 deletions

File tree

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-json-editor",
3-
"version": "0.1.8",
3+
"version": "0.2.0",
44
"authors": [
55
"Rodik Hanukaev <rodik@rodik.me>",
66
"Topaz Bar <topaz1008@gmail.com>"

demo/app.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,7 @@ angular.module('demoApp', ['angular-json-editor']).config(function (JSONEditorPr
4646
$scope.mySchema = $http.get('schema.json');
4747

4848
// Values can be a promise from anywhere
49-
$scope.myStartVal = $timeout(function () {
50-
return {
51-
age: 20
52-
};
53-
54-
}, 1500);
49+
$scope.myStartVal = $http.get('startval.json');
5550

5651
}).controller('SyncButtonsController', function ($scope) {
5752

demo/schema.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@
2020
"type": "boolean",
2121
"title": "Is cool?",
2222
"required": true
23+
},
24+
"info": {
25+
"type": "object",
26+
"name": "Information",
27+
"properties": {
28+
"phone": {
29+
"type": "integer",
30+
"name": "phone"
31+
}
32+
}
2333
}
2434
}
2535
}

demo/startval.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "myname",
3+
"age": 20,
4+
"isCool": true,
5+
"info": {
6+
"phone": 1234
7+
}
8+
}

dist/angular-json-editor.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ angular.module('angular-json-editor', []).provider('JSONEditor', function () {
6969
}
7070
}],
7171
link: function (scope, element, attrs, controller, transclude) {
72-
var valueToResolve,
73-
startValPromise = $q.when({}),
72+
var startValPromise = $q.when({}),
7473
schemaPromise = $q.when(null);
7574

7675
scope.isValid = false;
@@ -83,21 +82,15 @@ angular.module('angular-json-editor', []).provider('JSONEditor', function () {
8382
}
8483
if (angular.isObject(scope.startval)) {
8584
// Support both $http (i.e. $q) and $resource promises, and also normal object.
86-
valueToResolve = scope.startval;
87-
if (angular.isDefined(valueToResolve.$promise)) {
88-
startValPromise = $q.when(valueToResolve.$promise);
89-
90-
} else {
91-
startValPromise = $q.when(valueToResolve);
92-
}
85+
startValPromise = $q.when(scope.startval);
9386
}
9487

9588
// Wait for the start value and schema to resolve before building the editor.
9689
$q.all([schemaPromise, startValPromise]).then(function (result) {
9790

9891
// Support $http promise response with the 'data' property.
9992
var schema = result[0].data || result[0],
100-
startVal = result[1];
93+
startVal = result[1].data || result[1];
10194
if (schema === null) {
10295
throw new Error('angular-json-editor: could not resolve schema data.');
10396
}

dist/angular-json-editor.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-json-editor",
3-
"version": "0.1.8",
3+
"version": "0.2.0",
44
"repository": {
55
"type": "git",
66
"url": "git://github.com/rodikh/angular-json-editor.git"

src/angular-json-editor.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ angular.module('angular-json-editor', []).provider('JSONEditor', function () {
6666
}
6767
}],
6868
link: function (scope, element, attrs, controller, transclude) {
69-
var valueToResolve,
70-
startValPromise = $q.when({}),
69+
var startValPromise = $q.when({}),
7170
schemaPromise = $q.when(null);
7271

7372
scope.isValid = false;
@@ -80,21 +79,15 @@ angular.module('angular-json-editor', []).provider('JSONEditor', function () {
8079
}
8180
if (angular.isObject(scope.startval)) {
8281
// Support both $http (i.e. $q) and $resource promises, and also normal object.
83-
valueToResolve = scope.startval;
84-
if (angular.isDefined(valueToResolve.$promise)) {
85-
startValPromise = $q.when(valueToResolve.$promise);
86-
87-
} else {
88-
startValPromise = $q.when(valueToResolve);
89-
}
82+
startValPromise = $q.when(scope.startval);
9083
}
9184

9285
// Wait for the start value and schema to resolve before building the editor.
9386
$q.all([schemaPromise, startValPromise]).then(function (result) {
9487

9588
// Support $http promise response with the 'data' property.
9689
var schema = result[0].data || result[0],
97-
startVal = result[1];
90+
startVal = result[1].data || result[1];
9891
if (schema === null) {
9992
throw new Error('angular-json-editor: could not resolve schema data.');
10093
}

0 commit comments

Comments
 (0)