admin管理员组文章数量:1404949
On the portfolio selection page, I can either enter an account number or input a name.
When I enter an account number 979-9638403-03
and then click on the Search
button
A modal is correctly displayed with the client's data
My problem
If the user's account is incorrect, for example 123-4
Another modal displays that the input is incorrect.
For now, everything is fine, but when I close the modal.
The Selection confirmation
modal appears, and it bothers me a lot!
In fact, the second modal should not appear if there is an error.
I think the problem seems to be here?
...
const modalRef = this.modalService.show(SelectPortfolioResultModalComponent, {
...NOT_CLOSABLE_MODAL_OPTIONS,
class: "modal-dialog-centered modal-lg",
ariaLabelledBy: "modal-error-title",
initialState: {
isLoading: true,
},
});
...
Here is the full code
export class SelectPortfolioComponent implements OnDestroy {
private unsubscribe$ = new Subject<void>();
search = new SelectPortfolioModel();
account: number;
constructor(
private service: SelectPortfolioService,
private modalService: BsModalService,
private router: Router
) {}
ngOnDestroy(): void {
this.unsubscribe$.next();
this.unsubscribe$plete();
}
submit(): void {
const modalRef = this.modalService.show(
SelectPortfolioResultModalComponent,
{
...NOT_CLOSABLE_MODAL_OPTIONS,
class: "modal-dialog-centered modal-lg",
ariaLabelledBy: "modal-error-title",
initialState: {
isLoading: true,
},
}
);
modalRef
.content!.selectedPortfolio.pipe(takeUntil(this.unsubscribe$))
.subscribe((val: SelectPortfolio | undefined) => {
if (val) {
this.service
.selectPortfolio(val)
.pipe(takeUntil(this.unsubscribe$))
.subscribe(() => {
this.router.navigate(["/portfolio/valorisation"]);
});
}
modalRef?.hide();
});
this.service
.getPortfolios(this.search)
.pipe(takeUntil(modalRef.content!.selectedPortfolio))
.subscribe((res) => {
if (modalRef) {
modalRef.content!.portfolios = res.PTF;
const noResults = res.RETURNLIST.find(
(item) => item.CODE === ApiResponseCodeEnum.Sch00
);
if (noResults) {
modalRef.content!.errorMessage = noResults.TEXTE;
}
modalRef.content!.isLoading = false;
}
});
}
}
Thank you for your help and the time you dedicated to my problem.
On the portfolio selection page, I can either enter an account number or input a name.
When I enter an account number 979-9638403-03
and then click on the Search
button
A modal is correctly displayed with the client's data
My problem
If the user's account is incorrect, for example 123-4
Another modal displays that the input is incorrect.
For now, everything is fine, but when I close the modal.
The Selection confirmation
modal appears, and it bothers me a lot!
In fact, the second modal should not appear if there is an error.
I think the problem seems to be here?
...
const modalRef = this.modalService.show(SelectPortfolioResultModalComponent, {
...NOT_CLOSABLE_MODAL_OPTIONS,
class: "modal-dialog-centered modal-lg",
ariaLabelledBy: "modal-error-title",
initialState: {
isLoading: true,
},
});
...
Here is the full code
export class SelectPortfolioComponent implements OnDestroy {
private unsubscribe$ = new Subject<void>();
search = new SelectPortfolioModel();
account: number;
constructor(
private service: SelectPortfolioService,
private modalService: BsModalService,
private router: Router
) {}
ngOnDestroy(): void {
this.unsubscribe$.next();
this.unsubscribe$plete();
}
submit(): void {
const modalRef = this.modalService.show(
SelectPortfolioResultModalComponent,
{
...NOT_CLOSABLE_MODAL_OPTIONS,
class: "modal-dialog-centered modal-lg",
ariaLabelledBy: "modal-error-title",
initialState: {
isLoading: true,
},
}
);
modalRef
.content!.selectedPortfolio.pipe(takeUntil(this.unsubscribe$))
.subscribe((val: SelectPortfolio | undefined) => {
if (val) {
this.service
.selectPortfolio(val)
.pipe(takeUntil(this.unsubscribe$))
.subscribe(() => {
this.router.navigate(["/portfolio/valorisation"]);
});
}
modalRef?.hide();
});
this.service
.getPortfolios(this.search)
.pipe(takeUntil(modalRef.content!.selectedPortfolio))
.subscribe((res) => {
if (modalRef) {
modalRef.content!.portfolios = res.PTF;
const noResults = res.RETURNLIST.find(
(item) => item.CODE === ApiResponseCodeEnum.Sch00
);
if (noResults) {
modalRef.content!.errorMessage = noResults.TEXTE;
}
modalRef.content!.isLoading = false;
}
});
}
}
Thank you for your help and the time you dedicated to my problem.
Share asked Mar 10 at 8:59 MarinaLaGrandeMarinaLaGrande 3032 gold badges3 silver badges7 bronze badges1 Answer
Reset to default 0I think the previous subscriptions are still existing, which might be causing the double popup issue, it could be due to the usage of HTML with same id, name or something else. Or due to the observables being still active even when the modal gets destroyed.
Try take(1)
instead of takeUntil
which completes on first emission.
submit(): void {
...
modalRef
.content!.selectedPortfolio.pipe(take(1))
本文标签:
版权声明:本文标题:angular - Incorrect display of the 'Selection confirmation' modal in case of an error during portfolio search - 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744854973a2628718.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论