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})))