I have a code. It copies the content (of a certain view) after clicking on the button and then moves to another subpage where the copied items are. The problem is that the copied element is displayed only after the page is refreshed. Anyone can help me solve this mystery?
duplicate(){
this.landingPageService.getLandingPageItem(this.landingPageData.id).subscribe(
next => {
this.loading = true;
const copiedLandingPage = LandingPage.LandingPageFromDefinition(next),
copyLandingPage = LandingPage.GenerateCreationDTO(
copiedLandingPage.content,
`${copiedLandingPage.name} (copy)`
);
copyLandingPage.lpType = copiedLandingPage.lpType;
copyLandingPage.lastUpgraded = copiedLandingPage.lastUpgraded;
this.landingPageService
.createLandingPageItem(copyLandingPage)
.subscribe(
() => {
this.toastGenerator.lpContentCreation.success();
this.refreshSubject.next();
},
() => {
this.loading = false;
this.toastGenerator.lpContentCreation.failure();
}
);
},
() => {
this.toastGenerator.lpContentCreation.failure();
}
);
this.router.navigate(['/landing-page']);
}
<button (click)="duplicate()">Kopiuj</button>