this is the BehaviorSubject
getting value:
private searchClinicByParams$: BehaviorSubject<SearchClinicByParamsProps> = new BehaviorSubject(initialSearchParams);
here is my method needs to compose the vaues:
getParams() {
const values = this.searchClinicByParams$.pipe(
map((data) => data)
);
console.log('values', values);
}
at present above map not returns any value.
here is my get method:
clinicList$ = this.http
.get<AddClinicProps[] | null>(
this.URL
`hfs-admin/customer-application/clinics?name=OUS&adminUserName=${this.getParams()}`
)
.pipe(
map((clinics) => clinics),
catchError(this.handleError)
);
how can i get return value at this.getParams()
or what is the correct way to do it?
CodePudding user response:
Your getParams()
function has a misleading name, it doesn't get
anything since you are not returning anything, I always suggest explicitly setting the return type for your function, in this case, it should be an Observable
of type SearchClinicByParamsProps
given your example:
getParams(): Observable<SearchClinicByParamsProps> {
return this.searchClinicByParams$.asObservable();
}
And then, in your function where you are making the HTTP call:
clinicList$ = this.getParams().pipe(
mergeMap((params) => this.http.get(`${this.url}hfs-admin/customer-application/clinics?name=OUS&adminUserName=${params}}`)),
catchError(this.handleError)
)
I assume somewhere in your application, something is listening to clinicList$
, so when it subscribes, you will get your response.
CodePudding user response:
There're 2 things not being done right logically.
getParams()
is not returning anything.- You are using
getParams()
as if it is returning astring
Despite the naming of your functions, you may either
- Subscribe the value from
searchClinicByParams$
to a local variable and use it in your HTTP request. - Return the observable in
getParams()
and pipe it to your HTTP request with one of the mapping operators.