File tree Expand file tree Collapse file tree 6 files changed +41
-1
lines changed
HarryPotter/src/app/components Expand file tree Collapse file tree 6 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 11import { Component , OnInit } from '@angular/core' ;
22import { AppService } from 'src/app/app.service' ;
33import { IBookType } from 'src/app/models' ;
4+ import { takeUntil } from 'rxjs/operators' ;
5+ import { Subject } from 'rxjs' ;
46
57@Component ( {
68 selector : 'app-books' ,
@@ -9,8 +11,12 @@ import { IBookType } from 'src/app/models';
911} )
1012export class BooksComponent implements OnInit {
1113 books :Array < IBookType > = [ ] ;
14+ unSubscribeAll = new Subject < any > ( ) ;
1215 constructor ( private appService :AppService ) {
1316 this . appService . getBooks ( )
17+ . pipe (
18+ takeUntil ( this . unSubscribeAll )
19+ )
1420 . subscribe ( data => {
1521 this . books = data ;
1622 } ) ;
Original file line number Diff line number Diff line change 11import { Component , OnInit } from '@angular/core' ;
22import { AppService } from 'src/app/app.service' ;
33import { IPersonType } from 'src/app/models/personItem.model' ;
4+ import { takeUntil } from 'rxjs/operators' ;
5+ import { Subject } from 'rxjs' ;
46
57@Component ( {
68 selector : 'app-characters' ,
@@ -9,8 +11,12 @@ import { IPersonType } from 'src/app/models/personItem.model';
911} )
1012export class CharactersComponent implements OnInit {
1113 characters :Array < IPersonType > = [ ] ;
14+ unSubscribeAll = new Subject < any > ( ) ;
1215 constructor ( private appService :AppService ) {
1316 this . appService . getCharacters ( )
17+ . pipe (
18+ takeUntil ( this . unSubscribeAll )
19+ )
1420 . subscribe ( data => {
1521 this . characters = data ;
1622 } ) ;
Original file line number Diff line number Diff line change 11import { Component , OnInit } from '@angular/core' ;
22import { AppService } from 'src/app/app.service' ;
33import { IFilmType } from 'src/app/models' ;
4+ import { takeUntil } from 'rxjs/operators' ;
5+ import { Subject } from 'rxjs' ;
46
57@Component ( {
68 selector : 'app-films' ,
@@ -9,8 +11,13 @@ import { IFilmType } from 'src/app/models';
911} )
1012export class FilmsComponent implements OnInit {
1113 films : Array < IFilmType > = [ ] ;
14+ unSubscribeAll = new Subject < any > ( ) ;
1215 constructor ( private appService : AppService ) {
13- this . appService . getFilms ( ) . subscribe ( ( data ) => ( this . films = data ) ) ;
16+ this . appService . getFilms ( )
17+ . pipe (
18+ takeUntil ( this . unSubscribeAll )
19+ )
20+ . subscribe ( ( data ) => ( this . films = data ) ) ;
1421 }
1522
1623 ngOnInit ( ) : void { }
Original file line number Diff line number Diff line change 11import { Component , OnInit } from '@angular/core' ;
22import { AppService } from 'src/app/app.service' ;
33import { IHouseType } from 'src/app/models' ;
4+ import { takeUntil } from 'rxjs/operators' ;
5+ import { Subject } from 'rxjs' ;
46
57@Component ( {
68 selector : 'app-houses' ,
@@ -9,8 +11,13 @@ import { IHouseType } from 'src/app/models';
911} )
1012export class HousesComponent implements OnInit {
1113 houses :Array < IHouseType > = [ ] ;
14+ unSubscribeAll = new Subject < any > ( ) ;
15+
1216 constructor ( private appService :AppService ) {
1317 this . appService . getHouses ( )
18+ . pipe (
19+ takeUntil ( this . unSubscribeAll )
20+ )
1421 . subscribe ( data => {
1522 this . houses = data ;
1623 } ) ;
Original file line number Diff line number Diff line change 11import { Component , OnInit } from '@angular/core' ;
22import { AppService } from 'src/app/app.service' ;
33import { IPersonType } from 'src/app/models/personItem.model' ;
4+ import { takeUntil } from 'rxjs/operators' ;
5+ import { Subject } from 'rxjs' ;
46
57@Component ( {
68 selector : 'app-staff' ,
@@ -9,8 +11,13 @@ import { IPersonType } from 'src/app/models/personItem.model';
911} )
1012export class StaffComponent implements OnInit {
1113 staff :Array < IPersonType > = [ ] ;
14+ unSubscribeAll = new Subject < any > ( ) ;
15+
1216 constructor ( private appService :AppService ) {
1317 this . appService . getStaff ( )
18+ . pipe (
19+ takeUntil ( this . unSubscribeAll )
20+ )
1421 . subscribe ( data => {
1522 this . staff = data ;
1623 } ) ;
Original file line number Diff line number Diff line change 11import { Component , OnInit } from '@angular/core' ;
22import { AppService } from 'src/app/app.service' ;
33import { IPersonType } from 'src/app/models/personItem.model' ;
4+ import { takeUntil } from 'rxjs/operators' ;
5+ import { Subject } from 'rxjs' ;
46
57@Component ( {
68 selector : 'app-students' ,
@@ -9,8 +11,13 @@ import { IPersonType } from 'src/app/models/personItem.model';
911} )
1012export class StudentsComponent implements OnInit {
1113 students :Array < IPersonType > = [ ] ;
14+ unSubscribeAll = new Subject < any > ( ) ;
15+
1216 constructor ( private appService :AppService ) {
1317 this . appService . getStudents ( )
18+ . pipe (
19+ takeUntil ( this . unSubscribeAll )
20+ )
1421 . subscribe ( data => {
1522 this . students = data ;
1623 } ) ;
You can’t perform that action at this time.
0 commit comments