问题描述
我需要更新父组件中的 memoriesCount 值 - app.component.html 在导航栏下拉菜单
计数值的来源来自 childcomponent (home.component.ts)
app.component.html
.....
<button mat-menu-item>Memories collected : {{memoriseCount}}</button>
.....
home.component.ts
//inside Api call function
//appref is app component reference
this.appref.updateCount(this.allData.length);
app.component.ts
memoriseCount = 0;
....
updateCount(count:number)
{
this.memoriseCount = count
console.log(this.memoriseCount) //shows updated value
}
....
ngAfterContentChecked()
{
this.changeDetectorRef.detectChanges();
}
我试过 ngzone.run()、changeDetectorRef.markForCheck(),没有任何帮助。
菜单看起来像
控制台
memoriesCount 变量值已更新但未反映在菜单中(角度 UI)
你能帮我吗?
提前确认。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)