I want to trigger changes in landing.component.ts once I make changes in cites.component.ts
mediator.service.ts
@Injectable()
export class MediatorService {
private updateValue$: BehaviorSubject<any> = new BehaviorSubject('');
valueObs = this.updateValue$.asObservable();
constructor() {}
setValue(value: any) {
this.updateValue$.next(value);
}
}
cites.component.ts
@Component({
selector: 'cites',
templateUrl: './cites.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CitesComponent {
constructor(public mediator: MediatorService)
{}
private displayProgress(process: Promise<any>, message: string) {
return process.then(() => {
this.mediator.setValue(true);
}).catch((error: Error) => console.error(error))
}
}
landing.component.ts
@Component({
selector: 'landing',
templateUrl: 'landing.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class LandingComponent {
constructor(private mediator: MediatorService) {
this.mediator.valueObs?.subscribe((data: any) => {
if (data) {
this.changeValue();
}
})
changeValue()() {
//logic
}
}
}
I want LandingComponent to detect changes whenever I am subscribing to the BehaviorSubject and data is true. It is working if I am keeping ChangeDetectionStrategy as default in LandingComponent, but I want to keep ChangeDetectionStrategy.OnPush to improve performance.
I am new in Angular, so please help me with this issue.