0
典型情況:我通過http獲取數據並將它們存儲到ngrx/store中。但數據包含字符串而不是JS Date對象。我應該在哪裏轉換它們?將字符串轉換爲日期的位置?
- 在服務
this.http(...).map(convert).subscribe(store.dispatch(new AddAction))
- 在店內
case add: convert(payload); return state
還是在行動的減速機:
export class AddMany implements Action { readonly type = addMany constructor(public payload: FinishedCall[]) { this.payload = this.convertData(payload) } }
我想我應該做的服務,但我怕獲得非常大的服務文件
這取決於你和業務對象的設計。如果您更喜歡在打字稿代碼中始終使用JS Date類型,則儘可能早地將其轉換爲JS Date並儘可能從JS Date轉換爲字符串(如果也是必要的話)。創建一些輔助方法來進行轉換(如有必要),並在決定實現此目的的任何地方重新使用這些方法。 – Igor
我寧願儘快將日期轉換爲日期 – x1site
好的,那麼你就知道你的問題的答案。 – Igor