Skip to content
This repository was archived by the owner on Apr 30, 2018. It is now read-only.

Commit 2b9223e

Browse files
committed
made json editing pretty
1 parent edf1e83 commit 2b9223e

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

src/views/home.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ <h3>Fields</h3>
4949
ng-class="{'has-error': formFieldsError}">
5050
<textarea class="form-control"
5151
ng-model="formFieldsStr"
52-
rows="5">
52+
rows="15">
5353
</textarea>
5454
</div>
5555
</div>

src/views/home.js

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
11
'use strict';
22
app.controller('home', function($scope, $parse, $rootScope) {
3+
// Public Methods
4+
$scope.onSubmit = function onSubmit() {
5+
$scope.submittedData = $scope.formData;
6+
};
7+
8+
$scope.toPrettyJSON = function(obj, tabWidth) {
9+
var strippedObj = angular.copy(obj);
10+
var result = JSON.stringify(strippedObj, null, Number(tabWidth));
11+
return result;
12+
};
13+
14+
// Private Methods
15+
16+
// Events
17+
$scope.$watch('formFieldsStr', function onOptionsUpdated(newValue, OldValue) {
18+
try {
19+
$scope.formFields = $parse(newValue)({});
20+
$scope.formFieldsError = false;
21+
} catch (e) {
22+
// eat $parse error
23+
// console.log('Formly Demo App Error: error parsing data, changes not applied');
24+
$scope.formFieldsError = true;
25+
}
26+
});
27+
$scope.$watch('formOptionsStr', function onOptionsUpdated(newValue, OldValue) {
28+
try {
29+
$scope.formOptions = $parse(newValue)({});
30+
$scope.formOptionsError = false;
31+
} catch (e) {
32+
// eat $parse error
33+
// console.log('Formly Demo App Error: error parsing data, changes not applied');
34+
$scope.formOptionsError = true;
35+
}
36+
});
37+
338
// Public Vars
439
$scope.formFields = [{
540
type: 'email',
@@ -98,43 +133,8 @@ app.controller('home', function($scope, $parse, $rootScope) {
98133
};
99134
$scope.submittedData = null;
100135
$scope.formData = {};
101-
$scope.formFieldsStr = JSON.stringify($scope.formFields);
102-
$scope.formOptionsStr = JSON.stringify($scope.formOptions);
136+
$scope.formFieldsStr = $scope.toPrettyJSON($scope.formFields, 4);
137+
$scope.formOptionsStr = $scope.toPrettyJSON($scope.formOptions, 4);
103138
$scope.formFieldsError = false;
104139
$scope.formOptionsError = false;
105-
106-
// Public Methods
107-
$scope.onSubmit = function onSubmit() {
108-
$scope.submittedData = $scope.formData;
109-
};
110-
111-
$scope.toPrettyJSON = function(obj, tabWidth) {
112-
var strippedObj = angular.copy(obj);
113-
var result = JSON.stringify(strippedObj, null, Number(tabWidth));
114-
return result;
115-
};
116-
117-
// Private Methods
118-
119-
// Events
120-
$scope.$watch('formFieldsStr', function onOptionsUpdated(newValue, OldValue) {
121-
try {
122-
$scope.formFields = $parse(newValue)({});
123-
$scope.formFieldsError = false;
124-
} catch (e) {
125-
// eat $parse error
126-
// console.log('Formly Demo App Error: error parsing data, changes not applied');
127-
$scope.formFieldsError = true;
128-
}
129-
});
130-
$scope.$watch('formOptionsStr', function onOptionsUpdated(newValue, OldValue) {
131-
try {
132-
$scope.formOptions = $parse(newValue)({});
133-
$scope.formOptionsError = false;
134-
} catch (e) {
135-
// eat $parse error
136-
// console.log('Formly Demo App Error: error parsing data, changes not applied');
137-
$scope.formOptionsError = true;
138-
}
139-
});
140140
});

0 commit comments

Comments
 (0)