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 44 < h2 > Mes appareils</ h2 >
55 < p > Mis à jour le : {{ lastUpdate | async | date: 'd MMMM y' | uppercase }}</ p >
66 < ul class ="list-group ">
7- < app-appareil *ngFor ="let appareil of appareils "
7+ < app-appareil *ngFor ="let appareil of appareils; let i = index "
88 [appareilName] ="appareil.name "
9- [appareilStatus] ="appareil.status "> </ app-appareil >
9+ [appareilStatus] ="appareil.status "
10+ [index] ="i "> </ app-appareil >
1011 </ ul >
1112 < button class ="btn btn-success "
1213 [disabled] ="!isAuth "
Original file line number Diff line number Diff line change 11< li [ngClass] ="{'list-group-item': true,
22 'list-group-item-success': appareilStatus === 'allumé',
33 'list-group-item-danger': appareilStatus === 'éteint'} ">
4- < div style ="width:20px;height:20px;background-color:red; "
5- *ngIf ="appareilStatus === 'éteint' "> </ div >
4+
65 < h4 [ngStyle] ="{color: getColor()} "> Appareil : {{ appareilName }} -- Statut : {{ appareilStatus }}</ h4 >
76 < 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+
815</ li >
Original file line number Diff line number Diff line change 11import { Component , Input , OnInit } from '@angular/core' ;
2+ import { AppareilService } from '../services/appareil.service' ;
23
34@Component ( {
45 selector : 'app-appareil' ,
@@ -10,8 +11,10 @@ export class AppareilComponent implements OnInit {
1011
1112 @Input ( ) appareilName : string ;
1213 @Input ( ) appareilStatus : string ;
14+ @Input ( ) index : number ;
1315
14- constructor ( ) { }
16+ constructor ( private appareilService : AppareilService ) {
17+ }
1518
1619 ngOnInit ( ) {
1720 }
@@ -23,4 +26,12 @@ export class AppareilComponent implements OnInit {
2326 return 'red' ;
2427 }
2528 }
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+ }
2637}
Original file line number Diff line number Diff line change @@ -25,4 +25,12 @@ export class AppareilService {
2525 appareil . status = 'éteint' ;
2626 }
2727 }
28+
29+ switchOnOne ( i : number ) {
30+ this . appareils [ i ] . status = 'allumé' ;
31+ }
32+
33+ switchOffOne ( i : number ) {
34+ this . appareils [ i ] . status = 'éteint' ;
35+ }
2836}
You can’t perform that action at this time.
0 commit comments