【发布时间】:2016-07-26 15:41:53
【问题描述】:
在我的 app.component.html 中,我创建了一个自定义组件(联系人表组件),在我将商店中的连接用户更新为其他人后,该组件应该会获得一个新值(帐户)。
app.component.html:
<contact-table [contacts]="connectedAccount$ |async"></contact-table>
app.component.ts:
export class AppComponent implements OnInit
{
private connectedAccount$: Observable<Account>;
constructor(private store:Store<any>) {
this.connectedAccount$ = this.store
.select(state=> state.connectedAccountReducer.connectedAccount);
this.connectedAccount$
.subscribe(account1=> {
//the app prints any new account that comes up. It's working here.
console.log(account1);
});
}
public ngOnInit() {
this.store.dispatch({
type: updateConnectedAccount,
payload: {
connectedAccount: ACCOUNTS[0]
}
});
}
}
AppComponent 类中的订阅效果很好,可以触发任何出现的更新。
问题是 app.component.html 中的异步管道没有将新帐户发送到联系人表组件。我认为他不会收到任何更新的通知。
我试图查看发送到联系人表组件的内容, 我看到他在第一次创建联系表组件时只得到一个值,而且它的未定义。这是不可能的,因为我的 reducer 函数为我的应用程序的初始状态创建了一个空 Account 对象。
你注意到我错过了什么吗?
【问题讨论】:
-
您的联系表组件是什么样的?
标签: javascript angular rxjs ngrx