我当前正在使用Angular,并且我有一个网页,要求我将数据传递到另一个页面。
创建多个记录(映射到模型)
this.activatedRoute.data.subscribe(({ model] }) => {
setTimeout(() => {
this.ngbModalRef = this.modalService.open(... as Component, { size: 'lg', backdrop: 'static' });
this.ngbModalRef.componentInstance.model = model;
this.ngbModalRef.result.then(
result => {
console.log(result);
// this.router.navigate(['/order', { outlets: { popup: null } }]);
//this.ngbModalRef = null;
},
reason => {
console.log(reason);
// this.router.navigate(['/order', { outlets: { popup: null } }]);
//this.ngbModalRef = null;
}
);
}, 0);
});
this.activatedRoute.params.subscribe((params: any) => {
setTimeout(() => {
this.ngbModalRef = this.modalService.open(... as Component, {
size: 'lg',
backdrop: 'static'
});
this.ngbModalRef.componentInstance.listOfNum = params['listOfNum'];
this.ngbModalRef.result.then(
result => {
this.router.navigate(['/order', { outlets: { popup: null } }], {
replaceUrl: true,
queryParamsHandling: 'merge'
});
this.ngbModalRef = null;
},
reason => {
this.router.navigate(['/order', { outlets: { popup: null } }], {
replaceUrl: true,
queryParamsHandling: 'merge'
});
this.ngbModalRef = null;
}
);
}, 0);
});
请告知我该怎么做才能检索这两则消息。我只能按此顺序获取模型数据。
答案 0 :(得分:0)
您可以只使用rxjs forkjoin方法。
Forkjoin正在获得一个可观察的数组,并且当它们全部完成时就会触发。
forkJoin(
this.activatedRoute.data,
this.activatedRoute.params
).subscribe(([model, params]) => {
this.ngbModalRef = this.modalService.open(... as Component, {
size: 'lg',
backdrop: 'static'
});
this.ngbModalRef.componentInstance.listOfNum = params['listOfNum'];
this.ngbModalRef.componentInstance.model = model;
});
但是请记住,当两个都完成时,它会并且只有触发。