###前提・実現したいこと
*ngFor="let sensor of sensors"で取得したデータの中の値に応じてクラスを指定する方法がわかりません。
isErrorがtrueの時にクラスをerrorに指定したいです。
###該当のソースコード
html
1<table class="sensor-table"> 2 <thead> 3 <tr> 4 <td class="header" colspan="10">一覧 5 <button class="menu_btn" type="button" (click)="onClickMenu()">⋮</button> 6 </td> 7 </tr> 8 <tr> 9 <th></th> 10 <th>番号</th> 11 <th>エラー</th> 12 <th>警報</th> 13 <th>場所</th> 14 <th></th> 15 <th>温度(℃)</th> 16 <th>湿度(%)</th> 17 <th>日時</th> 18 <th></th> 19 </tr> 20 </thead> 21 <tbody> 22 <tr *ngFor="let sensor of sensors"> 23 <td> 24 <button class="color_btn" type="button" (click)="onClickColor(sensor)">色</button> 25 </td> 26 <td class="station">{{sensor.station}}</td> 27 <td>{{sensor.error}}</td> 28 <td>{{sensor.alarm}}</td> 29 <td class="location">{{sensor.location}}</td> 30 <td> 31 <button class="history_btn" type="button" (click)="onClickHistory(sensor)">履歴</button> 32 </td> 33 <td class="temperature">{{sensor.temperature}}</td> 34 <td class="humidity">{{sensor.humidity}}</td> 35 <td>{{sensor.date}}</td> 36 <td class="extra"></td> 37 </tr> 38 </tbody> 39</table> 40
###表示用
typescript
1export const SENSORS: Sensor[] = [ 2 { 3 color: null, 4 station: 1, 5 error: null, 6 isError: false, 7 alarm: 0, 8 isAlarm: true, 9 location: '第1', 10 temperature: 92, 11 humidity: 65.2, 12 date: '11/11 11:11' 13 }, 14 { 15 color: null, 16 station: 2, 17 error: null, 18 isError: false, 19 alarm: null, 20 isAlarm: false, 21 location: '第2', 22 temperature: 45, 23 humidity: 65.2, 24 date: '11/11 11:11' 25 }, 26 { 27 color: null, 28 station: 3, 29 error: null, 30 isError: false, 31 alarm: null, 32 isAlarm: false, 33 location: '第3', 34 temperature: 45, 35 humidity: 65.2, 36 date: '11/11 11:11' 37 }, 38 { 39 color: null, 40 station: 4, 41 error: 0, 42 isError: true, 43 alarm: null, 44 isAlarm: false, 45 location: '第4', 46 temperature: 24, 47 humidity: 65.2, 48 date: '11/11 11:11' 49 }, 50 { 51 color: null, 52 station: 5, 53 error: 0, 54 isError: true, 55 alarm: 0, 56 isAlarm: true, 57 location: '第5', 58 temperature: 51, 59 humidity: 65.2, 60 date: '11/11 11:11' 61 }, 62 { 63 color: null, 64 station: 6, 65 error: null, 66 isError: false, 67 alarm: null, 68 isAlarm: false, 69 location: '第6', 70 temperature: 49, 71 humidity: 65.2, 72 date: '11/11 11:11' 73 }, 74 { 75 color: null, 76 station: null, 77 error: null, 78 isError: false, 79 alarm: null, 80 isAlarm: false, 81 location: null, 82 temperature: null, 83 humidity: null, 84 date: null 85 } 86]; 87
###試したこと
[ngClass]="{'error': sensor.isError}"
###補足情報(言語/FW/ツール等のバージョンなど)
言っている意味が分からなかったらすみません。
指摘していただければ補足いたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/12/06 08:24
2017/12/06 08:26