如何在角度服务中编写后调用



>我有一个服务,它接受我的输入如下,

{
  "overviewPreferences": {
    "selectedRole": [{
      "code": "PRACTITIONER"
    }],
    "selectedDomainList": [{
      "code": "2",
      "name": "HR"
    },
    {
      "code": "3",
      "name": "PAYROLL"
    }]
  }
}

我声明我的接口如下,

export interface UserDomain {
  code: string;
  value: string;
  selected: boolean;
}

我的服务,

updateUserSelectedDomains(code: String): Observable<any> {
  return this.http.post<UserDomain>(`/adpi/rest/core/v2/business-intelligence/workers/${aoId}/preferences") `, request)
    .pipe(
      map(data => this.data = data),
    );  
}

在这里我想知道界面应该是什么?是我发送的请求还是我得到的响应。我不确定我是否正确。任何人都可以查看我的代码吗?谢谢。

post<ResponseType>

强类型返回的可观察量。因此,调用此方法会返回一个可观察量,因此当您订阅可观察量时,观察者会收到 ResponseType 的对象。

 // pass postbody object from your component to service method, so service will read 
 // parameter value in reqBody .
 //Then it will pass to post call API 
 let postBody = {
        "overviewPreferences": {
            "selectedRole": [{
                "code": "PRACTITIONER"
            }],
            "selectedDomainList": [{
                "code": "2",
                "name": "HR"
            },
            {
                "code": "3",
                "name": "PAYROLL"
            }]
          }
 } 
servicename.updateUserSelectedDomains(postBody).subscribe( (response)=>{
       console.log(response);
 })


// =============== Service code ====================
updateUserSelectedDomains(reqBody): Observable<any> {
   return this.http.post<UserDomain>(`/adpi/rest/core/v2/business- 
   intelligence/workers/${aoId}/preferences" `, reqBody)                    
}

相关内容

  • 没有找到相关文章

最新更新