I'm working on a feature for a web portal, for a user to "preview" some changes they have made to the data before saving it to the database. I've made a service and have two components, one that emits change events and the other that (is supposed to) listen and then update itself with the preview.
I want the preview to open in a new tab.
My service is
@Injectable()
export class PreviewService {
private hub = new Subject<Hub>();
hubUpdated = this.hub.asObservable();
updateHubPreview(hub: Hub) {
this.hub.next(hub);
}
constructor() {
}
}
My emitting component emits events by
emitChange(): void {
this.previewService.updateHubPreview(this.hub);
window.open(`hubs/preview/mock/${this.hub.id}`);
// I also tried [routerLink=...] target="_blank" in the template
}
And my preview component is
constructor(private hubService: HubService, private route: ActivatedRoute,
private previewService: PreviewService) {
this.hub = new Hub();
previewService.hubUpdated.subscribe(value => {
console.log("hello!");
this.hub = value;
});
}
In the newly opened window, nothing happens.