I am facing an issue with camera entries on an angular website. Whenever I click on an entry, a new window opens to display the camera livestream. However, I am having trouble with the subscribe functionality.
Important note: Once the window is open, subsequent clicks on the list should not create new windows but rather add the livestreams to the existing window.
When I click, I first open the window and then trigger my service method. But for some reason, the subscribe in the OnInit() method does not work.
OnClick:
this.externalWindow = window.open(
'/livesplit',
'',
'width=' + window.innerWidth + ',height=' + window.innerHeight
);
//call service to add a cameraconfig
this.settingsService.changeCurrentCameraLivesplit(result);
OnInit in the opened component:
this.settingsService.currentCameraLivesplit.subscribe(currentCameraLivesplit => {
//this is never hit..
if (currentCameraLivesplit) {
this.currentcameraList.push(currentCameraLivesplit );
}
});
My Service:
private cameraLivesplitSource = new BehaviorSubject(null);
currentCameraLivesplit = this.cameraLivesplitSource.asObservable();
changeCurrentCameraLivesplit(currentCameraLivesplit: CameraConfig[]) {
this.cameraLivesplitSource.next(currentCameraLivesplit);
}
Can anyone spot what mistake I might be making?
Additional info: The service is added in the app.module.ts under providers
I attempted to create a Stackblitz(example string should be included under the "add" button in the second window [only click the "add" button in the first window!])
Stackblitz editor: https://stackblitz.com/edit/angular-k9h1mn
Stackblitz app: