1- import { Component , OnInit } from '@angular/core' ;
1+ import { Component , OnInit , OnDestroy } from '@angular/core' ;
22import { AppareilService } from '../services/appareil.service' ;
3+ import { Subscription } from 'rxjs/Subscription' ;
34
45@Component ( {
56 selector : 'app-appareil-view' ,
67 templateUrl : './appareil-view.component.html' ,
78 styleUrls : [ './appareil-view.component.scss' ]
89} )
9- export class AppareilViewComponent implements OnInit {
10+ export class AppareilViewComponent implements OnInit , OnDestroy {
1011
11- isAuth = false ;
1212 appareils : any [ ] ;
13+ appareilSubscription : Subscription ;
1314
1415 lastUpdate = new Promise ( ( resolve , reject ) => {
1516 const date = new Date ( ) ;
@@ -20,14 +21,15 @@ export class AppareilViewComponent implements OnInit {
2021 ) ;
2122 } ) ;
2223
23- constructor ( private appareilService : AppareilService ) {
24- setTimeout ( ( ) => {
25- this . isAuth = true ;
26- } , 3000 ) ;
27- }
24+ constructor ( private appareilService : AppareilService ) { }
2825
2926 ngOnInit ( ) {
30- this . appareils = this . appareilService . appareils ;
27+ this . appareilSubscription = this . appareilService . appareilsSubject . subscribe (
28+ ( appareils : any [ ] ) => {
29+ this . appareils = appareils ;
30+ }
31+ ) ;
32+ this . appareilService . emitAppareilSubject ( ) ;
3133 }
3234
3335 onAllumer ( ) {
@@ -42,4 +44,7 @@ export class AppareilViewComponent implements OnInit {
4244 }
4345 }
4446
47+ ngOnDestroy ( ) {
48+ this . appareilSubscription . unsubscribe ( ) ;
49+ }
4550}
0 commit comments