【发布时间】:2018-04-30 17:29:19
【问题描述】:
我正在了解效果,并尝试在搜索失败时发送警告通知。 我的搜索操作是这样定义的
export enum SearchActionTypes {
SearchActionSearch = '[Search] Action search',
SearchActionFulfilled = '[Search] Action search fulfilled',
SearchActionFailed = '[Search] Action search failed',
}
我的应用中有一个可以显示通知的服务,我正在尝试在分派 SearchActionFailed Action 时调用此服务。但是,我不知道如何为此构建效果。目前我在这里:
@Injectable()
export class NotificationEffects {
@Effect()
// show error notification when an illegal value is entered into search
searchFailEffect = this.actions$.pipe(
ofType(Search.SearchActionTypes.SearchActionFailed),
);
constructor(private actions$: Actions,
private notificationService: NotificationService) {}
}
我想在效果捕捉到动作时调用通知服务API,调用结构如下:
this.notificationService.createNotification('type', 'message'))
我不需要操作负载中的任何内容,只需在调度失败操作时调用此服务即可。但是,我不知道如何构建这种效果。我的主要问题是效果必须返回一个可观察的,但我不需要任何我只需要知道搜索操作何时失败的东西,因此我可以调用服务来显示通知,警告用户他们的输入是错误的
【问题讨论】:
标签: angular typescript rxjs ngrx-effects