【发布时间】:2021-11-03 22:25:52
【问题描述】:
我有一个密码。单击按钮后,它会复制(某个视图的)内容,然后移动到复制项目所在的另一个子页面。问题是复制的元素只有在页面刷新后才会显示。谁能帮我解开这个谜团?
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>
【问题讨论】:
-
在 Angular 中不要在实时页面上更新,因为它已经加载你应该用
any在事件监听器中写这个,这样它会自动更新 -
拜托,再写点东西,举个例子?
-
和hostListener有关吗?
-
不,我在谈论事件侦听器,等等我在答案中粘贴代码
标签: angular