teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

「試したこと」に関して…解決していませんが、URL先を再度見直し書き直しました。

2021/07/28 01:05

投稿

aoa02ssm
aoa02ssm

スコア1

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.testService.countTest(testID).subscribe(res => {
62
+ this.counter(testID).subscribe(testData => {
62
- // 1. subscribeで取得したデータを用いて(testData = res.body)
63
+ if (testData) {
63
- this.testData.next(res.body);
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
  ```