@@ -16,29 +16,29 @@ <h1><i class="fa fa-play"></i> Changing data with the Angular way</h1>
16
16
< tabset >
17
17
< tab heading ="Preview ">
18
18
< article class ="preview ">
19
- < div ng-controller ="angularWayChangeDataCtrl ">
20
- < form class ="form-inline " ng-submit ="addPerson() ">
21
- < table datatable ="ng " dt-options ="dtOptions " dt-column-defs ="dtColumnDefs " class ="row-border hover ">
19
+ < div ng-controller ="AngularWayChangeDataCtrl as showCase ">
20
+ < form class ="form-inline " ng-submit ="showCase. addPerson() ">
21
+ < table datatable ="ng " dt-options ="showCase. dtOptions " dt-column-defs ="showCase. dtColumnDefs " class ="row-border hover ">
22
22
< thead >
23
23
< tr >
24
24
< th >
25
25
< div class ="form-group ">
26
26
< label >
27
- < input class ="form-control " type ="number " name ="id " ng-model ="person2Add.id " value =""/>
27
+ < input class ="form-control " type ="number " name ="id " ng-model ="showCase. person2Add.id " value =""/>
28
28
</ label >
29
29
</ div >
30
30
</ th >
31
31
< th >
32
32
< div class ="form-group ">
33
33
< label >
34
- < input type ="text " class ="form-control " name ="firstName " ng-model ="person2Add.firstName " value =""/>
34
+ < input type ="text " class ="form-control " name ="firstName " ng-model ="showCase. person2Add.firstName " value =""/>
35
35
</ label >
36
36
</ div >
37
37
</ th >
38
38
< th >
39
39
< div class ="form-group ">
40
40
< label >
41
- < input type ="text " class ="form-control " name ="lastName " ng-model ="person2Add.lastName " value =""/>
41
+ < input type ="text " class ="form-control " name ="lastName " ng-model ="showCase. person2Add.lastName " value =""/>
42
42
</ label >
43
43
</ div >
44
44
</ th >
@@ -56,13 +56,13 @@ <h1><i class="fa fa-play"></i> Changing data with the Angular way</h1>
56
56
</ tr >
57
57
</ thead >
58
58
< tbody >
59
- < tr ng-repeat ="person in persons ">
59
+ < tr ng-repeat ="person in showCase. persons ">
60
60
< td > {{ person.id }}</ td >
61
61
< td > {{ person.firstName }}</ td >
62
62
< td > {{ person.lastName }}</ td >
63
63
< td >
64
- < button type ="button " ng-click ="modifyPerson($index) " class ="btn btn-warning "> < i class ="fa fa-edit "> </ i > </ button >
65
- < button type ="button " ng-click ="removePerson($index) " class ="btn btn-danger "> < i class ="fa fa-trash-o "> </ i > </ button >
64
+ < button type ="button " ng-click ="showCase. modifyPerson($index) " class ="btn btn-warning "> < i class ="fa fa-edit "> </ i > </ button >
65
+ < button type ="button " ng-click ="showCase. removePerson($index) " class ="btn btn-danger "> < i class ="fa fa-trash-o "> </ i > </ button >
66
66
</ td >
67
67
</ tr >
68
68
</ tbody >
@@ -73,29 +73,29 @@ <h1><i class="fa fa-play"></i> Changing data with the Angular way</h1>
73
73
</ tab >
74
74
< tab heading ="HTML ">
75
75
< div hljs >
76
- < div ng-controller ="angularWayChangeDataCtrl ">
77
- < form class ="form-inline " ng-submit ="addPerson() ">
78
- < table datatable ="ng " dt-options ="dtOptions " dt-column-defs ="dtColumnDefs " class ="row-border hover ">
76
+ < div ng-controller ="AngularWayChangeDataCtrl as showCase ">
77
+ < form class ="form-inline " ng-submit ="showCase. addPerson() ">
78
+ < table datatable ="ng " dt-options ="showCase. dtOptions " dt-column-defs ="showCase. dtColumnDefs " class ="row-border hover ">
79
79
< thead >
80
80
< tr >
81
81
< th >
82
82
< div class ="form-group ">
83
83
< label >
84
- < input autofocus class ="form-control " type ="number " name ="id " ng-model ="person2Add.id " value =""/>
84
+ < input class ="form-control " type ="number " name ="id " ng-model ="showCase. person2Add.id " value =""/>
85
85
</ label >
86
86
</ div >
87
87
</ th >
88
88
< th >
89
89
< div class ="form-group ">
90
90
< label >
91
- < input type ="text " class ="form-control " name ="firstName " ng-model ="person2Add.firstName " value =""/>
91
+ < input type ="text " class ="form-control " name ="firstName " ng-model ="showCase. person2Add.firstName " value =""/>
92
92
</ label >
93
93
</ div >
94
94
</ th >
95
95
< th >
96
96
< div class ="form-group ">
97
97
< label >
98
- < input type ="text " class ="form-control " name ="lastName " ng-model ="person2Add.lastName " value =""/>
98
+ < input type ="text " class ="form-control " name ="lastName " ng-model ="showCase. person2Add.lastName " value =""/>
99
99
</ label >
100
100
</ div >
101
101
</ th >
@@ -113,13 +113,13 @@ <h1><i class="fa fa-play"></i> Changing data with the Angular way</h1>
113
113
</ tr >
114
114
</ thead >
115
115
< tbody >
116
- < tr ng-repeat ="person in persons ">
116
+ < tr ng-repeat ="person in showCase. persons ">
117
117
< td > {{ person.id }}</ td >
118
118
< td > {{ person.firstName }}</ td >
119
119
< td > {{ person.lastName }}</ td >
120
120
< td >
121
- < button type ="button " ng-click ="modifyPerson($index) " class ="btn btn-warning "> < i class ="fa fa-edit "> </ i > </ button >
122
- < button type ="button " ng-click ="removePerson($index) " class ="btn btn-danger "> < i class ="fa fa-trash-o "> </ i > </ button >
121
+ < button type ="button " ng-click ="showCase. modifyPerson($index) " class ="btn btn-warning "> < i class ="fa fa-edit "> </ i > </ button >
122
+ < button type ="button " ng-click ="showCase. removePerson($index) " class ="btn btn-danger "> < i class ="fa fa-trash-o "> </ i > </ button >
123
123
</ td >
124
124
</ tr >
125
125
</ tbody >
@@ -130,40 +130,42 @@ <h1><i class="fa fa-play"></i> Changing data with the Angular way</h1>
130
130
</ tab >
131
131
< tab heading ="JS ">
132
132
< div hljs language ="js ">
133
- angular.module('datatablesSampleApp', ['ngResource', 'datatables']).
134
- controller('angularWayChangeDataCtrl', function ($scope, $resource, DTOptionsBuilder, DTColumnDefBuilder) {
135
- var _buildPerson2Add = function (id) {
136
- return {
137
- id: id,
138
- firstName: 'Foo' + id,
139
- lastName: 'Bar' + id
140
- }
141
- };
133
+ angular.module('datatablesSampleApp', ['ngResource', 'datatables']).controller('AngularWayChangeDataCtrl', AngularWayChangeDataCtrl);
142
134
143
- $scope.persons = $resource('data1.json').query();
144
- $scope.dtOptions = DTOptionsBuilder.newOptions().withPaginationType('full_numbers');
145
- $scope.dtColumnDefs = [
135
+ function AngularWayChangeDataCtrl($resource, DTOptionsBuilder, DTColumnDefBuilder) {
136
+ var vm = this;
137
+ vm.persons = $resource('data1.json').query();
138
+ vm.dtOptions = DTOptionsBuilder.newOptions().withPaginationType('full_numbers');
139
+ vm.dtColumnDefs = [
146
140
DTColumnDefBuilder.newColumnDef(0),
147
141
DTColumnDefBuilder.newColumnDef(1),
148
142
DTColumnDefBuilder.newColumnDef(2),
149
143
DTColumnDefBuilder.newColumnDef(3).notSortable()
150
144
];
145
+ vm.person2Add = _buildPerson2Add(1);
146
+ vm.addPerson = addPerson;
147
+ vm.modifyPerson = modifyPerson;
148
+ vm.removePerson = removePerson;
151
149
152
- $scope.person2Add = _buildPerson2Add(1);
153
- $scope.addPerson = function () {
154
- $scope.persons.push(angular.copy($scope.person2Add));
155
- $scope.person2Add = _buildPerson2Add($scope.person2Add.id + 1);
156
- };
157
-
158
- $scope.modifyPerson = function (index) {
159
- $scope.persons.splice(index, 1, angular.copy($scope.person2Add))
160
- $scope.person2Add = _buildPerson2Add($scope.person2Add.id + 1);
161
- };
162
-
163
- $scope.removePerson = function (index) {
164
- $scope.persons.splice(index, 1);
165
- };
166
- });
150
+ function _buildPerson2Add(id) {
151
+ return {
152
+ id: id,
153
+ firstName: 'Foo' + id,
154
+ lastName: 'Bar' + id
155
+ };
156
+ }
157
+ function addPerson() {
158
+ vm.persons.push(angular.copy(vm.person2Add));
159
+ vm.person2Add = _buildPerson2Add(vm.person2Add.id + 1);
160
+ }
161
+ function modifyPerson(index) {
162
+ vm.persons.splice(index, 1, angular.copy(vm.person2Add));
163
+ vm.person2Add = _buildPerson2Add(vm.person2Add.id + 1);
164
+ }
165
+ function removePerson(index) {
166
+ vm.persons.splice(index, 1);
167
+ }
168
+ }
167
169
</ div >
168
170
</ tab >
169
171
< tab heading ="Example data ">
0 commit comments