I am working with Angular 4
I have a core component which is the parent component(menu, header, footer... included in core component) as below
CoreComponentHTML
<div class="wrapper" [ngClass] = "{'confirmation-body' : (showConfirm == true)}">
<app-header></app-header>
<app-sidemenu></app-sidemenu>
<div class="content-wrapper">
<app-breadcrumb> </app-breadcrumb>
<router-outlet></router-outlet>
</div>
</div>
<footer class="main-footer">
Copyright © 2017 <strong><a href="">XXXXXXXXXXXXXX Solutions</a>.</strong> All rights reserved.
</footer>
CoreComponent.ts
import { Component, OnInit,Injectable,AfterContentInit ,AfterViewInit, ViewEncapsulation, OnDestroy} from '@angular/core';
import { Router, ActivatedRoute, Params } from '@angular/router';
import { Event as RouterEvent,
NavigationStart,
NavigationEnd,
NavigationCancel,
NavigationError} from '@angular/router';
import {MenuService} from '../../shared/services/menu.service';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/toPromise';
import { ConfirmationSharedService } from 'app/sharecomponents/services/confirmation-shared.service';
@Component({
selector: 'app-core',
templateUrl: '../views/core.html'
})
export class CoreComponent implements OnInit, OnDestroy {
public userPin: any;
showConfirm: boolean;
alive: boolean = false;
constructor (private confirmationService: ConfirmationSharedService) {}
setUserPin (responce) {
console.log(responce, 'core pin core pin ')
if (responce !== 0) {
this.userPin = responce;
}
}
ngOnInit() {
this.confirmationService.getShowConfirm()
.subscribe(suc => {
console.log('1111111111111', suc);
this.showConfirm = suc});
}
ngOnDestroy() {
}
}
I have a LanguagesViewComponent in one module(xxxxxxxxxxxxx module), ConfirmationSharedService in another module(this module is imported in CoreModule )
i am setting a value to BehaviourSubject from LanguagesViewComponent which is declared in ConfirmationSharedService as below
this.confirmService.setShowConfirm(true);
BehaviourSubject is declared as below in ConfirmationSharedService
showConfirm: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
setShowConfirm(data) {
this.showConfirm.next(data);
}
getShowConfirm(): Observable<boolean> {
return this.showConfirm.asObservable();
}
the problem is when i set value to showConfirm in LanguagesViewComponent that new value is getting in CoreComponent(subscribed in ngOnInit() in CoreComponent)