File tree Expand file tree Collapse file tree 4 files changed +32
-5
lines changed Expand file tree Collapse file tree 4 files changed +32
-5
lines changed Original file line number Diff line number Diff line change 4
4
< h2 > Mes appareils</ h2 >
5
5
< p > Mis à jour le : {{ lastUpdate | async | date: 'd MMMM y' | uppercase }}</ p >
6
6
< ul class ="list-group ">
7
- < app-appareil *ngFor ="let appareil of appareils "
7
+ < app-appareil *ngFor ="let appareil of appareils; let i = index "
8
8
[appareilName] ="appareil.name "
9
- [appareilStatus] ="appareil.status "> </ app-appareil >
9
+ [appareilStatus] ="appareil.status "
10
+ [index] ="i "> </ app-appareil >
10
11
</ ul >
11
12
< button class ="btn btn-success "
12
13
[disabled] ="!isAuth "
Original file line number Diff line number Diff line change 1
1
< li [ngClass] ="{'list-group-item': true,
2
2
'list-group-item-success': appareilStatus === 'allumé',
3
3
'list-group-item-danger': appareilStatus === 'éteint'} ">
4
- < div style ="width:20px;height:20px;background-color:red; "
5
- *ngIf ="appareilStatus === 'éteint' "> </ div >
4
+
6
5
< h4 [ngStyle] ="{color: getColor()} "> Appareil : {{ appareilName }} -- Statut : {{ appareilStatus }}</ h4 >
7
6
< input type ="text " class ="form-control " [(ngModel)] ="appareilName ">
7
+
8
+ < button class ="btn btn-sm btn-success "
9
+ *ngIf ="appareilStatus === 'éteint' "
10
+ (click) ="onSwitch() "> Allumer</ button >
11
+ < button class ="btn btn-sm btn-danger "
12
+ *ngIf ="appareilStatus === 'allumé' "
13
+ (click) ="onSwitch() "> Eteindre</ button >
14
+
8
15
</ li >
Original file line number Diff line number Diff line change 1
1
import { Component , Input , OnInit } from '@angular/core' ;
2
+ import { AppareilService } from '../services/appareil.service' ;
2
3
3
4
@Component ( {
4
5
selector : 'app-appareil' ,
@@ -10,8 +11,10 @@ export class AppareilComponent implements OnInit {
10
11
11
12
@Input ( ) appareilName : string ;
12
13
@Input ( ) appareilStatus : string ;
14
+ @Input ( ) index : number ;
13
15
14
- constructor ( ) { }
16
+ constructor ( private appareilService : AppareilService ) {
17
+ }
15
18
16
19
ngOnInit ( ) {
17
20
}
@@ -23,4 +26,12 @@ export class AppareilComponent implements OnInit {
23
26
return 'red' ;
24
27
}
25
28
}
29
+
30
+ onSwitch ( ) {
31
+ if ( this . appareilStatus === 'allumé' ) {
32
+ this . appareilService . switchOffOne ( this . index ) ;
33
+ } else if ( this . appareilStatus === 'éteint' ) {
34
+ this . appareilService . switchOnOne ( this . index ) ;
35
+ }
36
+ }
26
37
}
Original file line number Diff line number Diff line change @@ -25,4 +25,12 @@ export class AppareilService {
25
25
appareil . status = 'éteint' ;
26
26
}
27
27
}
28
+
29
+ switchOnOne ( i : number ) {
30
+ this . appareils [ i ] . status = 'allumé' ;
31
+ }
32
+
33
+ switchOffOne ( i : number ) {
34
+ this . appareils [ i ] . status = 'éteint' ;
35
+ }
28
36
}
You can’t perform that action at this time.
0 commit comments