1- import { Component , OnInit , Input } from '@angular/core' ;
1+ import { Component , OnInit , Input , OnDestroy } from '@angular/core' ;
22import { UserItems } from 'src/app/shared/models/user-items.model' ;
3- import { Observable } from 'rxjs' ;
3+ import { Observable , Subscription } from 'rxjs' ;
44import { Store } from '@ngrx/store' ;
55import * as UsersActions from 'src/app/shared/state/actions/users.actions' ;
66import * as UsersSelectors from 'src/app/shared/state/selectors/users.selector' ;
77import { map } from 'rxjs/operators' ;
88import { UiService } from 'src/app/shared/services/ui.service' ;
99import { UserFullProfile } from 'src/app/shared/models/user-full-profile' ;
10- import { User } from 'src/app/shared/models/user.model' ;
10+
1111@Component ( {
1212 selector : 'app-user-result' ,
1313 templateUrl : './user-result.component.html' ,
1414 styleUrls : [ './user-result.component.scss' ]
1515} )
16- export class UserResultComponent implements OnInit {
16+ export class UserResultComponent implements OnInit , OnDestroy {
1717 @Input ( )
1818 user : UserItems ;
1919 $subData : Observable < UserFullProfile > ;
2020 selectedUser : UserFullProfile ;
21+ $usersSubscrition : Subscription ;
2122
2223 constructor (
2324 private store : Store < { selectedUser : UserFullProfile } > ,
@@ -29,7 +30,7 @@ export class UserResultComponent implements OnInit {
2930 onSelectUser ( selectedUser : UserItems ) : void {
3031 this . uiService . setTabSelected ( false ) ;
3132 this . store . dispatch ( new UsersActions . SetSelectedUser ( null ) ) ;
32- this . store
33+ this . $usersSubscrition = this . store
3334 . select ( UsersSelectors . selectSearchSubData )
3435 . pipe (
3536 map ( usersSubdata =>
@@ -45,4 +46,10 @@ export class UserResultComponent implements OnInit {
4546 this . uiService . setTabSelected ( true ) ;
4647 } ) ;
4748 }
49+
50+ ngOnDestroy ( ) : void {
51+ if ( this . $usersSubscrition ) {
52+ this . $usersSubscrition . unsubscribe ( ) ;
53+ }
54+ }
4855}
0 commit comments