如何仅在angular 5中完成线程执行后调用函数?
我试图在线程之后调用函数。但功能是 在完成线程之前被调用。我需要在哪里换车如何仅在angular 5中完成线程执行后调用函数?,angular,promise,rxjs,angular5,Angular,Promise,Rxjs,Angular5,我试图在线程之后调用函数。但功能是 在完成线程之前被调用。我需要在哪里换车 使用异步 this._listService.getListById(this.userName) .subscribe((response: any) => { if (response) { this.modelOpen(response); } }); filterList(){ console.log('Inside Filter List') } async modelO
使用异步
this._listService.getListById(this.userName)
.subscribe((response: any) => {
if (response) {
this.modelOpen(response);
}
});
filterList(){
console.log('Inside Filter List')
}
async modelOpen(response) {
await this._listServiceMod.loadListModel(response);
this.filterList();
}
使用异步尝试这种方法
this._listService.getListById(this.userName)
.subscribe((response: any) => {
if (response) {
this.modelOpen(response);
}
});
filterList(){
console.log('Inside Filter List')
}
async modelOpen(response) {
await this._listServiceMod.loadListModel(response);
this.filterList();
}
如果
过滤器列表
不依赖于前面方法的输出,则可以使用RxJs来处理这种情况
this._listService.getListById(this.userName).pipe(
mergeMap(response => this._listServiceMod.loadListModel(response))
).subscribe(response => {
this.filterList();
});
如果
filterList
不依赖于前面方法的输出,则可以使用RxJs来处理这种情况
this._listService.getListById(this.userName).pipe(
mergeMap(response => this._listServiceMod.loadListModel(response))
).subscribe(response => {
this.filterList();
});
将您的
loadListModel
方法更改为以下方法
loadListModel(data:any): Promise<any> {
let promise = this._listItemService.run(
this.loadListItem,
{
constants: appConstants
})
return promise.then((updatedAuthList)=> {
this._listItemService.terminate(promise);
return true;
});
}
签出此工作模式将您的
loadListModel
方法更改为以下方法
loadListModel(data:any): Promise<any> {
let promise = this._listItemService.run(
this.loadListItem,
{
constants: appConstants
})
return promise.then((updatedAuthList)=> {
this._listItemService.terminate(promise);
return true;
});
}
签出此工作将loadListModel更改为可观察的:
this._listServiceMod.loadListModel(response).pipe(
tap(() => this.filterList())
).subscribe()
将loadListModel更改为可观察的:
this._listServiceMod.loadListModel(response).pipe(
tap(() => this.filterList())
).subscribe()
你能展示一下
loadListModel()
的实现吗?这是什么意思?\u listServiceMod.loadListModel
返回如果你的模型很简单,你可以使用setTimeout
功能。你能展示一下loadListModel()的实现吗
?这个有什么作用。\u listServiceMod.loadListModel
返回如果您的模型很简单,您可以使用setTimeout
功能。我已经尝试过这种方法。但结果仍然是一样的。在调试器模式下,确定在终止承诺之前调用filterList()。我已经尝试过这种方法。但结果仍然是一样的。在调试器模式下,确定filterList()在终止承诺之前调用。我无法更改loadListModel方法,因为它也被其他组件使用。您可以为此创建重复的loadListModel
方法。我无法更改loadListModel方法,因为它也被其他组件使用。您可以为创建重复的loadListModel
方法在loadListModel()
之前,此filterList
仍在启动?使用此功能如何?如果需要,可以在我到家后编写一个示例filterList
在loadListModel()
之前仍处于激活状态?如何使用此示例?如果需要,可以编写一个示例,我在家尝试过,但filterList()甚至在loadListModel开始执行之前被调用。尝试过,但filterList()甚至在loadListModel开始执行之前被调用。