2017-08-29 57 views
0

我創造了這個ObservableRxJs:映射到匿名類型的對象

private accounts$: Observable<{type: string, alias: string}>; 

我需要一個Array<Account>映射到{type, alias}對象的流。到目前爲止,我試過這個:

this.accounts$ = this.store$ 
    .select(fromRoot.getDBoxAccountEntities) 
    .flatMap(accounts => accounts.map(account => {type: 'dbox', alias: account.dboxAccount})) 
    ... 

但是我收到編譯錯誤消息。

任何想法?

回答

1

您從箭頭函數返回一個對象,但方括號提示函數體。您需要圍繞退貨對象()

.flatMap(accounts => accounts.map(account => ({type: 'dbox', alias: account.dboxAccount})))