1
1
'use strict' ;
2
2
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
+
3
38
// Public Vars
4
39
$scope . formFields = [ {
5
40
type : 'email' ,
@@ -98,43 +133,8 @@ app.controller('home', function($scope, $parse, $rootScope) {
98
133
} ;
99
134
$scope . submittedData = null ;
100
135
$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 ) ;
103
138
$scope . formFieldsError = false ;
104
139
$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
- } ) ;
140
140
} ) ;
0 commit comments