我从事的一个项目基本上是通过一个名为ServiceHandler的中介类调用服务方法.在该组件中,Result变量的控制台输出为undefined
.
有没有解决这个问题的办法?
Component个
this.entityServiceHandler.saveEntityWithCondition(entity).subscribe(data => { this.result = data});
console.log(this.result);
ServiceHandler个
public saveEntityWithCondition(entity): Observable<Entity>{
var subject = new Subject<any>();
this.subscriptions.push(
forkJoin({
conditionTrue: this.entityService.isConditionTrue(entity.property)
}).subscribe(({ conditionTrue }) => {
if (conditionTrue) {
this.entityService.save(entity).subscribe(
(response: Entity) => {
subject.next(response);
},
(errorResponse: HttpErrorResponse) => {
}
)
}
},
err => {},
() => {
}));
return subject.asObservable();
}
Service个
public save(item: Entity) : Observable<Entity>{
public save(item: Entity): Observable<Entity> {
return this.httpClient.post<Entity>(`path`, item).pipe(catchError((err) => this.handleAndThrowError(err)));
}
}