回答編集履歴
2
修正
test
CHANGED
@@ -8,17 +8,19 @@
|
|
8
8
|
|
9
9
|
```JavaScript
|
10
10
|
|
11
|
-
var testVar = [];
|
12
|
-
|
13
|
-
|
14
|
-
|
15
11
|
var app = angular.module('myApp', []);
|
16
12
|
|
17
13
|
|
18
14
|
|
19
15
|
//遷移元コントローラー
|
20
16
|
|
21
|
-
app.controller('AppController', function($scope) {
|
17
|
+
app.controller('AppController', function($scope,GlobalService) {
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
var testVar = [];
|
22
|
+
|
23
|
+
|
22
24
|
|
23
25
|
$scope.fruits = [
|
24
26
|
|
@@ -50,7 +52,7 @@
|
|
50
52
|
|
51
53
|
}
|
52
54
|
|
53
|
-
|
55
|
+
GlobalService.testVar = testVar;
|
54
56
|
|
55
57
|
});
|
56
58
|
|
@@ -62,15 +64,21 @@
|
|
62
64
|
|
63
65
|
//遷移先コントローラー
|
64
66
|
|
65
|
-
app.controller('NewAppController', function($scope) {
|
67
|
+
app.controller('NewAppController', function($scope,GlobalService) {
|
66
68
|
|
67
|
-
|
69
|
+
$scope.testVar = GlobalService.testVar;
|
68
70
|
|
69
|
-
|
71
|
+
});
|
70
72
|
|
71
|
-
|
72
73
|
|
74
|
+
|
75
|
+
|
76
|
+
|
73
|
-
|
77
|
+
//遷移先コントローラー
|
78
|
+
|
79
|
+
app.service('GlobalService', function() {
|
80
|
+
|
81
|
+
this.testVar;
|
74
82
|
|
75
83
|
});
|
76
84
|
|
1
コード修正
test
CHANGED
@@ -8,13 +8,17 @@
|
|
8
8
|
|
9
9
|
```JavaScript
|
10
10
|
|
11
|
-
var testVar;
|
11
|
+
var testVar = [];
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
-
angular.module('myApp', [])
|
15
|
+
var app = angular.module('myApp', []);
|
16
16
|
|
17
|
+
|
18
|
+
|
19
|
+
//遷移元コントローラー
|
20
|
+
|
17
|
-
|
21
|
+
app.controller('AppController', function($scope) {
|
18
22
|
|
19
23
|
$scope.fruits = [
|
20
24
|
|
@@ -34,25 +38,41 @@
|
|
34
38
|
|
35
39
|
$scope.check = function() {
|
36
40
|
|
37
|
-
|
41
|
+
|
38
42
|
|
39
43
|
angular.forEach($scope.fruits, function(value, index, array) {
|
40
44
|
|
41
45
|
if (value.checked) {
|
42
46
|
|
43
|
-
|
47
|
+
testVar.push(value.name);
|
44
48
|
|
45
49
|
console.log(value.name);
|
46
50
|
|
47
51
|
}
|
48
52
|
|
49
|
-
$scope.
|
53
|
+
//$scope.testVar = testVar; //これは不要
|
50
54
|
|
51
55
|
});
|
52
56
|
|
53
|
-
}
|
57
|
+
};
|
54
58
|
|
55
|
-
}
|
59
|
+
};
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
//遷移先コントローラー
|
64
|
+
|
65
|
+
app.controller('NewAppController', function($scope) {
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
var getTestVar = testVar //受け取り
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
//$scope.testVar;
|
74
|
+
|
75
|
+
});
|
56
76
|
|
57
77
|
```
|
58
78
|
|