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

質問編集履歴

1

コードの追加

2021/10/28 00:48

投稿

xxx0_0xxx
xxx0_0xxx

スコア9

title CHANGED
File without changes
body CHANGED
@@ -3,7 +3,8 @@
3
3
 
4
4
  rangeで数値を24まで回しています。
5
5
 
6
+
6
- ```ここに言語を入力
7
+ ```Typescript
7
8
  _.range(24).forEach((h) => {
8
9
  _.range(60).forEach((m) => {
9
10
  let index: number = h * 60 + m;
@@ -46,7 +47,7 @@
46
47
  条件として足らないのでしょうか?
47
48
  ※①〜④はコンソールに出力した結果です。
48
49
 
49
- ```ここに言語を入力
50
+ ```TypeScript
50
51
  console.log(h); // ① 0,1,2,3,4,5,6,7,8,9,10,11...23
51
52
  if (0 <= h && h < 12) {
52
53
  console.log(h); // ② 0,1,2,3,4,5,6,7,8,9,10,11
@@ -57,4 +58,33 @@
57
58
  };
58
59
  console.log(h); // ④ 0,1,2,3,4,5,6,7,8,9,10,11...23
59
60
  return this.ampm;
61
+ ```
62
+
63
+ ↓コメントを受けて追加しました。
64
+ ### 試したこと
65
+
66
+ HTML側では *ngIf を利用して表示させています。
67
+ これだと午前午後の表記になってしまいます。
68
+ これではngifの条件分岐がなされていないのでしょうか?
69
+
70
+ ```Angular
71
+ <th *ngIf="minute.isZeroMinute" rowspan="12"><ng-container *ngIf="am">{{am}}</ng-container><ng-container *ngIf="pm">{{pm}}</ng-container>{{minute.hourString}}<br>時</th>
72
+
73
+ ```
74
+
75
+ ```TypeScript
76
+
77
+ export class Component {
78
+
79
+ am: string = "";
80
+ pm: string = "";
81
+
82
+
83
+ if (0 <= h && h < 12) {
84
+ return this.am = "午前";
85
+ } else if (12 <= h && h < 24) {
86
+ return this.pm = "午後";
87
+ };
88
+
89
+ }
60
90
  ```