質問編集履歴
1
「試したこと」に関して…解決していませんが、URL先を再度見直し書き直しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -44,6 +44,7 @@
|
|
44
44
|
|
45
45
|
https://teratail.com/questions/129464
|
46
46
|
上記が近いのではと思い下記のように修正してみましたが、やはり関数内でif文が先に動いてしまうようです。
|
47
|
+
また、関数checkTESTの戻り値に関して「'void' 型の式は、真実性をテストできません。」というエラーが出ます。
|
47
48
|
```typescript
|
48
49
|
export class TestComponent implements OnInit {
|
49
50
|
|
@@ -57,19 +58,23 @@
|
|
57
58
|
|
58
59
|
}
|
59
60
|
|
60
|
-
checkTEST(testID: number, testCount: number){
|
61
|
+
checkTEST(testID: number, testCount: number) {
|
61
|
-
this.
|
62
|
+
this.counter(testID).subscribe(testData => {
|
62
|
-
|
63
|
+
if (testData) {
|
63
|
-
|
64
|
+
return Number(testData) > testCount;
|
65
|
+
} else {
|
66
|
+
return false;
|
67
|
+
}
|
64
68
|
});
|
65
|
-
|
66
|
-
// 2. if文で条件分岐し(if (testData))、値を返したい
|
67
|
-
if (testData) {
|
68
|
-
return Number(this.testData) < testCount;
|
69
|
-
} else {
|
70
|
-
return false;
|
71
|
-
}
|
72
69
|
}
|
70
|
+
counter(testID: number){
|
71
|
+
let testData;
|
72
|
+
this.testService.countTest(orgId).subscribe(res => {
|
73
|
+
testData = res.body;
|
74
|
+
this.testData.next(testData);
|
75
|
+
});
|
76
|
+
return this.testData;
|
77
|
+
}
|
73
78
|
|
74
79
|
}
|
75
80
|
```
|