Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular Typescript:处理onInit上服务调用之间依赖关系的最佳方法_Angular_Typescript - Fatal编程技术网

Angular Typescript:处理onInit上服务调用之间依赖关系的最佳方法

Angular Typescript:处理onInit上服务调用之间依赖关系的最佳方法,angular,typescript,Angular,Typescript,您好,我正在寻找处理onInit服务调用之间依赖关系的typescript最佳实践。 我有4个函数在它上面运行,前3个是填充3个子组件(过滤下降)。 然后返回一个包含选定过滤器值的数组。 当我选择了筛选值后,我想运行最后一个函数,该函数使用前3个函数中的值构建一个查询,然后发送数据请求。 然后使用该数据填充表格。 目前,在第三个函数的末尾调用第四个函数。 我觉得应该有更好的方法来处理异步调用,希望有人能给我指出正确的方向 this.getCatalogueStatuses();

您好,我正在寻找处理onInit服务调用之间依赖关系的typescript最佳实践。 我有4个函数在它上面运行,前3个是填充3个子组件(过滤下降)。 然后返回一个包含选定过滤器值的数组。 当我选择了筛选值后,我想运行最后一个函数,该函数使用前3个函数中的值构建一个查询,然后发送数据请求。 然后使用该数据填充表格。 目前,在第三个函数的末尾调用第四个函数。 我觉得应该有更好的方法来处理异步调用,希望有人能给我指出正确的方向

    this.getCatalogueStatuses();
    this.getCountries();
    this.getAgreementTypes()
    // dependent on function above for filtering
    this.getClaimTypeAndPrices();

听起来您可能需要一个
forkJoin
?():


这假设您的方法
This.getcatalogestatuses()、This.getCountries()和This.getAgreementTypes()
return
observeables

我是错的还是属于向这个堆栈站点询问最佳做法这是一个非常广泛的问题。你能分享一下你的尝试和你遇到的问题吗。就目前而言,这是一个“最佳实践”问题,对于本网站来说是离题的,因为没有正确的答案。话虽如此,看看反应式编程。也:
import { forkJoin } from 'rxjs';

...

forkJoin(
    this.getCatalogueStatuses(),
    this.getCountries(),
    this.getAgreementTypes(),
)
.subscribe(([catalogueStatuses, countries, agreementTypes]) => {
    // use return data for method below
    this.getClaimTypeAndPrices();
});