Angular将HttpClient服务方法作为参数传递给method

时间:2019-07-07 20:16:32

标签: angular typescript

我在Angular应用程序中使用了很多对话框,并且创建了大量重复代码,尤其是对于简单的CRUD操作而言。我重复的代码中唯一真正改变的是对HttpService方法的调用。其余的只是样板。

有没有一种方法可以将HttpClient服务方法传递给常规对话框方法?我将在Dialog方法内部为该HttpClient方法构建参数,因此我最初传入的任何内容都将无关紧要

我想做到这一点:

对话框方法:

crudPostDialog(dialogConfig: DialogModel, crudMethod: Observable < any > ) {
  // Do stuff and alter data to be passed to crudMethod.
  // Change crudMethod param value as it was passed as null.
  // Execute crudMethod call.
  crudMethod
    .pipe(
      take(1),
      takeUntil(this._destroyed$)
    )
    .subscribe((data: DialogDataReturnedModel) => {
      if (!data) {
        return;
      }
      // Do more stuff.
    });
}

调用方法:

this.crudPostDialog(dialogConfigModel, this._personService.addNewPerson(null));

0 个答案:

没有答案
相关问题