import { Component , OnInit , OnDestroy } from '@angular/core' ; import { ExerciseService } from '../../shared/exercise.service' ; import { SubscribeExercise } from './subscribe-exercise' ; import { TranslateService } from '@ngx-translate/core' ; import { Subscription } from 'rxjs' ; @ Component ( { selector : 'app-subscribe' , templateUrl : './subscribe.component.html' , styleUrls : [ './subscribe.component.scss' ] } ) export class SubscribeComponent implements OnInit , OnDestroy { exerciseTitle = 'subscribe' ; observableCode = `
  const observable = new Observable(subscriber => {
    subscriber.next(1);
    subscriber.next(2);
    subscriber.next(3);
  }).subscribe(x => console.log(x));

  // Logs:
  // 1
  // 2
  // 3
  ` ; subscribeCode = `
observable.subscribe();
  ` ; currentLanguage = '' ; onLangChangeSubscription : Subscription ; constructor ( private exerciseService , private translateService ) { } ngOnInit ( ) { this . exerciseService . newExercise ( new SubscribeExercise ( ) ) ; this . currentLanguage = this . translateService . currentLang ; this . onLangChangeSubscription = this . translateService . onLangChange . subscribe ( { next : ( ) => { this . currentLanguage = this . translateService . currentLang ; } } ) ; } ngOnDestroy ( ) { this . onLangChangeSubscription . unsubscribe ( ) ; } }