在我的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对象。
你有没有注意到我错过了什么?
你的contact-table组件是什么样的? –